my $str = "abcabcdefgabcdXfgabYdefgabcdZZg"; my $match = "abcdefg"; my $len = length($match); for my $i (0..length($str)-$len) { my $s = substr $str, $i, $len; my $x = $s ^ $match; $x =~ tr/\0//d; # equal characters xor to \0 print "'$s' at offset $i matched" unless length($x) > 1; } __END__ 'abcdefg' at offset 3 matched 'abcdXfg' at offset 10 matched 'abYdefg' at offset 17 matched