Which can be reduced to a one liner for files: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
perl -ni.bak -e 'print unless ( /^Header1$/ .. /^END LIST$/)' filenam +e
update: As to the way you have it.
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 oncemy $text = do { local $/; <FILE> }; if ($text =~ /^Header1.*?END LIST/m) { .... }
Note the \n is there to remove the blank lines that might result.my $text = do { local $/; <FILE> }; $text =~ s/^Header1.*?END LIST\n?//msg
-enlil
In reply to Re: match and remove across multiple lines
by Enlil
in thread match and remove across multiple lines
by dr_jgbn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |