sub countt{ ... my @arraystr =split(//,$string);#split the string acc. to each alphabet and pass it to the array. foreach my $alpha($string){ if ($alpha =~ /t/i){ # if 't' is found $count++; #increment the count return $count; # } }