It could be as simple as this:

while( $string =~ m/(SUMMARY.+?DESCRIPTION)/ig ) { print "Summary: $1\n" }

The while() loop continues looping as long as its condition is true. In this case, the condition is whether or not a match occurs. And by using the /g modifier, multiple matches can be detected within the same string. Each time a match occurs the internal position marker advances so that the next match will come after the current match. perlre and perlretut describe the use of the /g modifier in greater detail.

I removed the leading and trailing instances of .+?, because I don't think they were actually doing anything useful for you, and they potentially get in the way of repeated matches (the /g modifier). As you're probably aware, .+? says to non-greedily match one or more characters. If your only reason for that is to assure that there is at least one character separating matches, you could just do it with a single dot to the left and right of the capture. We're not trying to anchor to anything outside of the capture anyway, from what I can tell.


Dave


In reply to Re: Foreach Loop in Data Scraping by davido
in thread Foreach Loop in Data Scraping by MiriamH

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.