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