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