sub dehex { my ($s) = @_ ; $s =~ s/0[xX]((?:[0-9A-Fa-f]{2})+)/pack('U0H*', $1)/eg ; return $s if utf8::valid($s) ; ... worry ... return undef ?? } ;