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


in reply to How to create a DNS message in perl?

Use the unpack funtion to convert the name to hex:

$QNAME = unpack("H*", "www.google.com")

For more read:

perldoc -f unpack
and
perldoc -f pack