my $rx = qr/ ([abcd]) # a, b, c, or d -- stored in \1 .* # well, whatever (?!\1) # the next character can't be \1 ([abcd]) # a, b, c, or d -- stored in \2 .* # y'know, stuff (?!\1|\2) # next thing not \1 or \2 ([abcd]) # a, b, c, or d -- stored in \3 .* (?!\1|\2|\3) # next thing not \1, \2, or \3 [abcd] # you get the idea /x;