in reply to
Print a previous to previous of a matching line
open(FILE, "twentySeq1e-10.out") or die("Cannot open file");
my $line = $_;
if($line=~/# 0 hits found/)
The generalized solution would use an array. You use unshift() to add the line at the start of the array and you use pop() to remove the last line if the array has length n+1 (with n being the number of lines you want to remember). That is called a pipeline, queue, shift register or FIFO (first-in-first-out).