in reply to Print preceding line from text database

Tie::File will serve you well here.

use Tie::File ; my $data_file="learn.data"; my $search_for = 'foo' ; tie my @raw_data, 'Tie::File', $data_file or die ; for ( my $row = 0 ; $row < $#raw_data; ++$row ) { if ( $raw_data[ $row ] =~ /$search_for/ ) { my $matching_row = $raw_data[ $row ] ; my $previous_row = $raw_data[ $row - 1 ] ; my $following_row = $raw_data[ $row + 1 ] ; ### And so on and so forth... } }

_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche