$str1='It is a guide to action which ensures that the military always obey the commands of the party.'; chomp($str1); $str2='It is a guide to action that ensures that the military will forever heed Party commands is a guide.'; chomp($str2); @arr1=split(/\s+/, $str1); $n=0; for($i=0; $i<$#arr1;$i++) { $t1="$arr1[$i] $arr1[$i+1] $arr1[$i+2]"; if($str2=~/$t1/) { print "$t1\12"; $n++; } } print "\n No of matching is : $n"; #### The output is: It is a is a guide a guide to guide to action ensures that the that the military No of matching is : 6.