http://qs321.pair.com?node_id=296067


in reply to Interpolation in character class

The perlretut man page says "If you've been around Perl a while, all this talk of escape sequences may seem familiar. Similar escape sequences are used in double-quoted strings and in fact the regexps in Perl are mostly treated as double-quoted strings. This means that variables can be used in regexps as well. Just like double-quoted strings, the values of the variables in the regexp will be substituted in before the regexp is evaluated for matching purposes."

So the answer to your question is that your construction works because you would expect a double-quoted string to work that way. You could also use the octal excape syntax: /\A\020[^\020]/.

The reason \x{$a} doesn't work is the same reason that it doesn't work in a double-quoted string - probably that the double-quoted string interpolation mechanism is single-pass and not recursive. (This is only a guess.)