Like chromatic said, it is the .+ that is messing you up. You can make that non-greedy by appending a ?. So, your example might become:
while ( $string =~ m!(<a[^>]*>)(.+?</a[^>]*>)!ig ) { print "$1 \n"; print "$2 \n"; }
I tried that against a portion of your example string (after replacing the <'s and >'s), and it seemed to work ok. I'm pretty much a newbie, so I imagine there are better ways to do it then I have described. Edit: By the way, it's the "g" option on the regex that makes it work in that "while". I guess when it tries to do a multiple match, it will eventually fall off the end, and return a false. Without the "g", that while statement I used will run forever, as long as the string contains a single match to your regexp.

In reply to Re: Regex isn't performing like I think it should by jmarshall99
in thread Regex isn't performing like I think it should by Popcorn Dave

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.