use strict; chomp(my $s = <>); chomp(my $t = <>); my $c = 0; if ($t =~ /^(.)\g1+$/) { while ($s =~ s/(\Q$t\E)//) { $c++; } } else { while ($s =~ /(\Q$t\E)/g) { $c++; } } if ($c && (length($t) == 1 || $t =~ /^\.+$/)) { print("-1\n"); } else { print($c, "\n"); }