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