# assuming $left sequence is the longer one my $len = length($right); my @matches = map { (substr($left, $_, $len) ^ $right) =~ tr/\0/\0/ } 0 .. length($left) - $len;