sub countSubstring {
  my $str = shift;
  my $sub = quotemeta(shift);
  my $count = () = $str =~ /$sub/g;
  return $count;

}

print countSubstring("the three truths","th"), "\n"; 
print countSubstring("ababababab","abab"), "\n";