I'm not sure what exactly is the goal but here is more compact and likely faster code.
primer = "ATTAAACTCTTCATTCATCAGT";
sequence =
"GATGAAAAACACAAAAGTACGAATTAATTTGGTACGTTTCCACCATAATTATTGGTAAAAAGTCGTT\
ACAAACCCTAGTAAACACGATGAAACAAAGAGA";
primerChrs = Characters[primer];
sequenceChrs2 = Characters[sequence];
ListCorrelate[primerChrs, sequenceChrs2, {-1, 1}, 0,
Boole[SameQ[##]] &]
(* {0, 1, 1, 1, 1, 0, 3, 1, 1, 3, 4, 1, 3, 3, 4, 4, 3, 7, 2, 4, 3, 7, 8, \
7, 9, 5, 5, 7, 7, 6, 6, 11, 7, 3, 6, 8, 9, 6, 6, 6, 6, 4, 8, 10, 6, \
5, 8, 5, 7, 11, 5, 5, 9, 5, 3, 9, 8, 6, 5, 8, 5, 4, 10, 7, 5, 8, 7, \
5, 5, 7, 3, 5, 5, 7, 8, 7, 9, 6, 10, 5, 4, 5, 5, 5, 4, 10, 8, 8, 8, \
6, 4, 4, 6, 2, 5, 8, 4, 9, 7, 8, 4, 4, 5, 2, 4, 2, 4, 6, 3, 2, 3, 4, \
3, 2, 2, 3, 2, 1, 1, 0, 1} *)
It is almost identical to your version, except yours has an extra 0 at the front where you compare primer
to a string of all X
(probably that string was one too long and the end of the outer loop was one too soon).