use warnings;
use strict;
my $str1 = q/It is a guide to action which ensures that the military a
+lways obey the commands of the party./;
my $str2 = q/It is a guide to action that ensures that the military wi
+ll forever heed Party commands is a guide./;
my $n = 0;
while ( $str1 =~ /(?=(\S+\s+\S+\s+\S+))/g ) {
my $t1 = $1;
while ( $str2 =~ /($t1)/g ) {
print $1;
$n++;
}
}
print "No of matching is : $n";
but output of the above code comes like this:
It is at is ais a guideis a guides a guides a guidea guide toguide to actionuide to actionide to actionde to actione to actionensures that thensures that thesures that theures that theres that thees that thes that thethat the militaryhat the militaryat the militaryt the military
Not the expected output..
What i expected is:
It is a
is a guide
is a guide
a guide to
guide to action
ensures that the
that the military
And the maximum reference count of each word i want.. i.e in this case. "is a guide" is matched two times so its count is 2.
Any suggestions.