If you can't slurp the whole file then you could do something like this.

#! perl -slw use strict; my $buffer; while( <DATA> ) { $buffer .= $_; # Accumulate lines in a buffer # Use \s+ instead of space to allow for newlines between words # The /g option is required to set pos() if( $buffer =~ /Content\s+Compression\s+to\s+Date/g ) { print "Content Compression to Date found"; # Once you find something your looking for # throw away everything that preceded it with substr() substr( $buffer, 0, pos( $buffer ) ) =''; } } __DATA__ Content Compression to Date other stuff other stuff other stuff Content Compression to Date other stuff other stuff other stuff Content Compression to Date Content Compression to Date other stuff other stuff Content Compression to Date other stuff other stuff

Output

P:\test>test2 Content Compression to Date found Content Compression to Date found Content Compression to Date found Content Compression to Date found Content Compression to Date found

Notes:

You will need to use the /g option on ALL the regexes, even though you are only looking for the first match each time in order for pos to be set. (I never quite understood that?).

You will also need to do the substr thing to throw away everything already matched after each successful match.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

In reply to Re: multiple line regex by BrowserUk
in thread multiple line regex by js1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.