my @list; while (){ my @line = split/,/,$_; for (@line){ m/(AAA.\d)/; push @list, $1; } }