A \n regex backreference is not active in a character class; [^\1]
is equivalent to [^1] (Update: Nope. Not quite. See Update below.)
Try:
c:\@Work\Perl\monks>perl -wMstrict -le
"my $s = 'CCHHHCHHCHC';
print qq{'$s'};
;;
$s =~ s/(\w) (?!\1). \1/$1$1$1/xgi;
print qq{'$s'};
"
'CCHHHCHHCHC'
'CCHHHHHHHHC'
(note the use of the /x modifier — for clarity only).
Update: In fact, \1 in a character class is an octal escape sequence:
c:\@Work\Perl\monks\flappygoat>perl -wMstrict -le
"my $s = qq{\1\x01\o{001}\cA};
print 'match' if $s =~ /[^\1]/;
print 'count: ', $s =~ tr/\1//;
"
count: 4
(no match; nothing printed). Wonderful what you can find out if you actually test stuff.
Give a man a fish: <%-{-{-{-<
|