in reply to Reading a value two lines before the current line

You could also read the the file in backward using File::ReadBackwards, then when you find the line you need, just read two more.

I'm inclined to think that is the best solution to your problem assuming the file is of any size at all. Reading the file into an array is slow and memory inefficient and to read forward line by line, you'll have to remember the prior lines somehow, and that's going to involve a lot of data movement (if you use say 4 variables to store the prior lines--you'll be shuffling their values a lot) or a lot of memory (if you're putting the prior lines into an array), slowing your program down.

Edited to add example:
use File::ReadBackwards; $bw = File::ReadBackwards->new( 'log_file' ) or die "can't read 'log_file' $!" ; until ( $bw->eof ) { last if ($bw->readline =~ m/$search_string/); } $prior_line_1 = $bw->readline; $prior_line_2 = $bw->readline;