in reply to Lines above and Below a matched string

If the file is small, slurp the whole file into a scalar and use a regex of the general form

my $data = do{ local (*ARGV, $/) = 'text.file'; <>; }; print "$2,$1,$3" if $data =~ m[(DATE).*?(SOMETHING).*?(SOMETHINGELSE)]s;

The /s modifier allows . to match newlines, so the .*? will span lines. Add /g if you expect to find more than one occurance.

If your file is too big to slurp, then you could use a sliding buffer on the file. See Re: split and sysread() for some sample code.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller