in reply to Parsing arguments with surrounding garbage.

Don't use substitution here:
$string="garbage validcommand 1234 221 garbage 999 213 validcommand 1 +2 34 garbage"; while ($string =~ /validcommand\s+((\d+\s+)+)/g) { push @args, split /\s+/, $1; }