I see letter-by-letter overlapping with the code of the OP when run under ActiveState 5.8.9, and I assume this is the way the code 'doesn't work' under sarvan's 5.8.8. (As others have commented, it would be nice if sarvan would actually say how the code 'doesn't work'.)

The following modification produces the same output in AS 5.8.9 and Strawberries 5.10.1.5 and 5.12.3.0 (don't ask me just why; the answer is presumably in one of the perldelta docs):

>perl -wMstrict -le "my $str1 = q/It is a guide to action which ensures that the / . q/military always obey the commands of the party./ ; ;; my $n = 0; while ($str1 =~ m{ (?= (\b \S+ \s+ \S+ \s+ \S+ \b)) }xmsg) { my $t1 = $1; print qq{$t1}; $n++; } ;; print qq{No of matching is: $n}; " It is a is a guide a guide to guide to action to action which action which ensures which ensures that ensures that the that the military the military always military always obey always obey the obey the commands the commands of commands of the of the party No of matching is: 16

Note: The 5.10+ versions don't need the  \b assertions to produce the same result.

Update: Actually, the second  \b assertion in the regex above is redundant. The regex
    m{ (?= (\b \S+ \s+ \S+ \s+ \S+)) }xmsg
gives the output of the OP (which I think is what sarvan wants) under all Perl versions listed above.


In reply to Re: output differs in perl version by AnomalousMonk
in thread output differs in perl version by sarvan

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.