my $stretch = 10; my $mismatches = 1; substr $reference_str, 0, 0, 'x' x (length($small_str) - 1); $reference_str .= 'x' x (length($small_str) - 1); for my $start_pos (0 .. length($reference_str) - 1 - $stretch) { my $substr = substr $reference_str, $start_pos, length($small_str) - 1; my $xor = $small_str ^ $substr; for my $inner_pos (0 .. length($xor) - $stretch) { if ($stretch - $mismatches <= substr($xor, $inner_pos, $stretch) =~ tr/\0//) { my $match = substr $reference_str, $start_pos + $inner_pos, $stretch; next unless -1 == index $match, 'x'; say $start_pos + $inner_pos + 1 - length $small_str; say substr $small_str, $inner_pos, $stretch; say $match; } } }