http://www.perlmonks.org?node_id=747135

larryk has asked for the wisdom of the Perl Monks concerning the following question:

If I want to match a four letter word that starts and ends with the same character, I use: "test" =~ /^(.)..\1$/ - this is successful.

Now I want to match a four letter word that does not start and finish with the same letter, using: "test" =~ /^(.)..[^\1]$/ - this doesn't work; it's still a successful match.

It seems the backreference \1 is turning into an escaped literal within the character class.

P.S. ultimately, I'm trying to create a pattern that is able to say, "at some character position there either is or is not one of the preceeding characters," e.g."test" =~ /^(.)([^\1])([^\1\2])\1$/

   larryk                                          
perl -le "s,,reverse killer,e,y,rifle,lycra,,print"