in reply to Surprising capture of undef with zero repetitions

The feature is that perl returns one element for each capture group to preserve numbering (so $tmp[0] is the same as $1, $tmp[1] is $2 etc ...).
For example with my ($_a, $_b, $_c) = "ac" =~ /(a)?(b)?(c)?/;, you'll have $_c = 'c' and 'b' undef.
Removing the extra undef at the end of the list, or even in the middle for some special cases could have been possible, but it is actually fairly easy to do it yourself: @tmp = grep defined, /(a)?(b)?(c)?/; so the decision has been to provide the result with all the available information (undef matches at the end indicate that some groupes have not matched, this may be useful information) and let the user decide what to do with it, rather than choose on the user's behalf what information is useful or not.

Edit: so in your case (without the implicit match on $_), the solution would be: my @tmp = grep defined, "list $_[0]\n" =~ /^list\s+(\w+)(?:,(\w+))*$/m;