# $re is the pattern to match my @next_lines; while () { push @next_lines, scalar() if /$re/; }