in reply to match and remove across multiple lines

The flip flop operator (..) is good for this sort of thing.
use strict; use warnings; while (<DATA>) { print unless ( /^Header1$/ .. /^END LIST$/ ); } __DATA__ Header1 1 2 3 4 5 3 2 43 43 END LIST Header2 2 42 24 2 32 2 32 2 2 4 2 3 END LIST Header1 2 43 43 END LIST Header3 2 3 4 32 3 4 3 43 END LIST Header1 1 2 3 4 5 3 2 43 43 END LIST
Which can be reduced to a one liner for files:
perl -ni.bak -e 'print unless ( /^Header1$/ .. /^END LIST$/)' filenam +e

update: As to the way you have it.

my $text = do { local $/; <FILE> }; if ($text =~ /^Header1.*?END LIST/m) { .... }
You are missing the /s modifier as the . will not match newlines without it. Also if you just want to remove that stuff you might as well use s/// and then print the result (add the /g modifier if Header1 appears more than once
my $text = do { local $/; <FILE> }; $text =~ s/^Header1.*?END LIST\n?//msg
Note the \n is there to remove the blank lines that might result.

-enlil

Replies are listed 'Best First'.
Re: Re: match and remove across multiple lines
by dr_jgbn (Beadle) on Apr 24, 2004 at 04:40 UTC
    Thanks Enlil!!
    Appreciate it...boy o boy that was simple. I was looking through my beginning perl books for quite awhile and could not find this solution... Thanks again,
    Dr.J