perlfaq nodetype
faq_monk
<P>
You can use Perl's somewhat exotic <CODE>..</CODE> operator (documented in
[perlman:perlop|the perlop manpage]):
<P>
<PRE> perl -ne 'print if /START/ .. /END/' file1 file2 ...
</PRE>
<P>
If you wanted text and not lines, you would use
<P>
<PRE> perl -0777 -pe 'print "$1\n" while /START(.*?)END/gs' file1 file2 ...
</PRE>
<P>
But if you want nested occurrences of <CODE>START</CODE> through <CODE>END</CODE>, you'll run up against the problem described in the question in this
section on matching balanced text.
<P>
Here's another example of using <CODE>..</CODE>:
<P>
<PRE> while (<>) {
$in_header = 1 .. /^$/;
$in_body = /^$/ .. eof();
# now choose between them
} continue {
reset if eof(); # fix $.
}
</PRE>
<P>