my @lines; $/ = \80; # assume a block size of 80 while (<$file>) { push @lines, $_; my $str = join "", @lines; if ($str =~ /searchword/) { my $loc = tell $file - pos $str; print "Found a match starting after $loc.\n"; }; if (@lines > 2) { shift @lines }; };