It's already explained why this happens, because the character
class is created at compile time. But this gives us the right
hint to "fix" the regex: use a delayed regex.
($_ = 'aaab') =~ m[(.)((??{"[^$1]"}))] and print "$1|$2";
a|b
That works too. The only problem with that was this came up whilst I was trying to tackle your "N-Queens with pure regex" problem. I thought I was onto a more efficient solution, but......it didn't work ;)
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail