$cnt =0 $str="hi hi harshmane hi hi"; if ($str=~/([hi]+)/g) { $cnt++; } print $cnt;