Extract command-line arguments from a list, removing matches from the original array