in reply to output differs in perl version

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.