my @array; while ($line = ) { if ($line =~ /regexp/) { push(@array, $line); } } #### my @array; while ($line = ) { if ($line =~ /(regexp)/) { # surrounding the regexp with brackets push(@array, $1); # holds the result of the match from the last regexp } }