$string =~ '0x0102'; $output = pack('H*', substr($string, 2)); print($output); # "\x01\x02"