http://www.perlmonks.org?node_id=986525


in reply to String to hex

This seems pretty legible

sub str_to_hex { my $str = shift; return "0x" . substr(unpack("H*", $str), 0, 4); } print str_to_hex("COM7") . "\n"; # outputs: 0x434f