http://qs321.pair.com?node_id=177163


in reply to accumulating rex-exp matches in an array

And lo, it was written in the book of perlop, that one would be able to call upon the /g modifier, and do that which ye seek:
my @list; while (<INFILE>) { push @list, m/(AAA\.\d)/g; }

And, yea, moreover it is also not good practice to blindly assign $1 and its brethren without checking whether they are defined first, or using the glories of the list assignment which hath been provided for such uses and others

OK, enough of that ... your code has a problem, in that it will attempt to match and will push the value of $1 onto the array WHETHER OR NOT that match is successful. The terse example above is functionally (in the present context) equivalent to:

while (<INFILE>) { if (my @matches = m/(AAA\.\d)/g ) { push @list, @matches; } }

The match operator, with parens and /g, returns a list of the matches in the line, which get assiged to the @matches array.

Oh, yeah, and you'll notice that since . is a metacharacter in regular expressions, you should escape it if you want to match a literal "." rather than "any character (except newline)".

HTH