You can have something that kind of behaves like "multiple captures" by matching in list context and using look ahead assertions to make sure the current match still allows for the rest of the string to match. Not sure about performance, but it's a solution that doesn't require to embed code in the regex.

use Data::Dump qw/pp/; chomp( (undef, $_, undef, @words) = <> ); # If multiple words are identical as lowercase, only the last one will + be kept %restore_case = map { lc reverse, $_ } @words; $list = join '|', keys %restore_case; # Match any word in the list, only if it can be followed by words in t +he list until the end of the string my @result = map { $restore_case{$_} } /($list)(?=(?:$list)*$)/g; pp @result;
You know that there is a match or the end of the string after each match, so after the first match you know the regex will always succeed at the current position. Adding \G can make that more explicit, and force the overall match to start at position 0.


In reply to Re: Multi_captures needed by Eily
in thread Multi_captures needed by rsFalse

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.