use Encode "encode"; sub U2Entity { return '&#x'.unpack("H*", encode("ucs2be", shift)).';'; } #### sub Any2Hex { return unpack("H*", shift); }