http://www.perlmonks.org?node_id=94275


in reply to Newbie Text Parsing Question

My version, editted from the first reply.
foreach my $fn (<*.log>) { # start with 3 entries to ensure 3 lines my @fifo = ('','',''); open I, $fn or warn("Couldn't open $fn: $!"), next; while (<I>) { #Add current line on one end and remove the first entry push(@fifo,$_); shift(@fifo); if (/monk/) { print '-'x40 ,$/; print "From file [$fn]:\n\n"; print @fifo; print '-'x40 , $/; } } close I; }

--
Brovnik