All of the answers so far have not correctly replicated the behaviour of the original code - I don't know if this is really an issue but multiple START and END (sic! and not STOP - there's a typo in the original post) aren't matched. To do so I would suggest:

my @good_stuff = $stuff =~ /^START\n(.*?)^END$/gms; # or alternatively with START and END around my @good_stuff = $stuff =~ /(^START$.*?^END$)/gms;
This captures into the array @good_stuff and can then be further processed. This is quite similar to the solution from tadman. Note the /m modifier to let ^ and $ match inside the string just before and after a newline. The /s modifier ensures that .*? matches everything including newlines.

Another issue are the benchmarks done here in this thread. These don't show anything, it depends on the structure of the real data.

So to sum up, you should always run benchmark tests on some real data to get an impression on how different methods compare. Try different test strings both for matching success and failure cases.

-- Hofmator


In reply to Re: Efficiently Extracting a Range of Lines (was: Range This) by Hofmator
in thread Efficiently Extracting a Range of Lines (was: Range This) by skazat

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.