m{ (?: # either ^ # start of string | # or (.) (?!\1) # any character that is not followed by a duplicate ) # now proceed as before, keeping in mind this is now the second capture ([A-Za-z]) \2 (?!\2) }x;