The problem you're seeing is that \u is meaningless in the context of a regular expression. It is meaningful in the context of a quoted string (double-quoted style interpolation), but you're not allowing that to happen. The literal string '\utext' is finding its way to the regular expression engine. There is no double-quotish interpolation occurring at the stage where you would need it to happen. Your sense is right; double-quotish interpolation isn't a recursive descent mechanism; it only happens once. You could change '\utext' to "\utext" so that the interpolation occurs at the time that $var is defined. Or you could pre-process $var before passing it to the RE engine.
The RE compiler does interpolate $var into m//, but it doesn't dive into multiple depths to see if it can find anything within $var that might be interpolated somehow. Imagine this example (which clearly doesn't perform multi-level interpolation):
$var1 = 'test'; $var2 = '$var1' $string = 'test'; print "Match\n" if $string =~ m/$var2/;
This seems a little rediculous, and it's not surprising that the match fails. You're asking for a similar interpolation to occur, and it won't.
Dave
In reply to Re: \U, \E and friends interpolation in regex operators
by davido
in thread \U, \E and friends interpolation in regex operators
by Hue-Bond
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |