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