#! /usr/bin/perl $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; %result=(); %output=(); for($i=0; $i<$#arr1;$i++) { $t1="$arr1[$i] $arr1[$i+1] $arr1[$i+2]"; @pattern_word_count=split(/\s/, $t1); $space_count=@pattern_word_count; if($space_count == 3) { if($str2=~/$t1/) { $occurence=`echo $str2 | grep -o '$t1' |wc -l`; chomp($occurence); $result{$occurence}=$t1; print $i+1,"\t\t",$occurence,"\t\t\t$t1\n"; $n++; } if($str1=~/$t1/) { $occurence1=`echo $str1 | grep -o '$t1' |wc -l`; chomp($occurence1); $output{$occurence1}=$t1; print $i+1,"\t\t",$occurence1,"\t\t\t$t1\n"; } } } print "\n\nTotal Matches : $n\n";