Two things:
- This doesn't work, you have to use chr(hex($2))otherwise the numbers are converted as integer values and not hex!
- You don't need two pairs of capturing parens, this is unnecessary extra work for the regex engine.
So the correct solution is
s/\[0x([a-f0-9A-F]{1,2})\]/chr(hex($1))/eg;
-- Hofmator