use Data::Dumper; $h{"a", 1, "b", 2} = 1; $h{a1b2} = 2; $_ = Dumper \%h; s/(\P{IsPrint})/"\\x{".sprintf "%04x}", ord $1/ge; print