in reply to Why is variable interpolation suppressed in \x{$xxx} replacement ?

Welcome to Perl's world of little languages!

There are many little languages inside Perl, and some little languages even have little languages inside them! Regular expressions for instance are a little language inside Perl, different semantics, different syntax, different grammar. But inside this little language, there are several other little languages. For instance, the content of [ ], doesn't follow the syntax and semantic rules of the rest of the regular expressions. Another little language inside regular expressions is the \x{ } construct. Different syntax/semantics here as well. And one of the differences is that they don't interpolate variables.

Having said that, it's still possible to do what you want, once you've evalled strings repeatedly:

#!/usr/bin/perl -w use strict; use constant DLE=>0x10; my $dle = sprintf ("%02X", DLE); my $msg = pack ("CCCCC", 0x31, 0x32, 0x10, 0x10, 0x33); # match $dle's expanded, replacement is not expanded ? $msg =~ s/(??{ eval qq!"\\x{$dle}\\x{$dle}"! })/qq!"\\x{$dle}"!/gee; printf ("%02x " x length($msg) . "\n", unpack ("C*", $msg)); __END__ 31 32 10 33

Abigail