While the other solutions offered work on a file that is already entirely slurped into memory, it is possible to combine the flip flop operator (".." in scalar context) with line oriented file processing. You could try something like:

my ( @revision_array, @current_revision); while (<DATA>) { my $status; if ( $status = /<!-- Start_of_revision-->/ .. /<!-- End_of_revision- +->/ and $status != 1 and $status !~ /E/ ) { push @current_revision, $_; } if ( $status =~ /E/ ) { push @revision_array, join '', @current_revision; undef @current_revision; } } my $count; for my $revision (@revision_array) { print 'revision ', ++$count, ": \n$revision\n"; } __DATA__ <head>somthing</head> <!-- Start_of_revision--> some revised text <!-- End_of_revision--> some other regular tags and stuff <br> <!-- Start_of_revision--> another revision <!-- End_of_revision--> the rest of the document

That obscure line about testing $status to see if it contains the letter 'E' is to detect the state change from "inside the matching area" to "outside the matching area".

For more information, see 'perldoc perlop'. Search for "Range Operators", and pay attention to the paragraphs about scalar context. If you are crazy, and enjoy using OO beyond its range of usefulness, then you might like Bit::FlipFlop.

-Colin.

WHITEPAGES.COM | INC


In reply to Re: pattern matching by cmeyer
in thread pattern matching by Anonymous Monk

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.