my $ls = 0; while () { if (/^LINESCORE/) { $ls++; } #linescore is greater than 1(we found LINESCORE) and less than 3(we haven't read 2 lines yet) elsif ($ls && $ls < 3) { chomp; push @line, $_; $ls++ } }