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

You are not encoding $QNAME correctly. Each segment of the host name (i.e., 'www', 'google', and 'com' here) must be preceded by the character length of the segment and the whole thing terminated by a null byte; and you drop the dots (not needed, as the length bytes tell their positions). See http://www.tcpipguide.com/free/t_DNSNameNotationandMessageCompressionTechnique.htm

So in your case, you need something like

$QNAME="\03www\06google\03com\00;"

Note that this matches what you see in wireshark if you run a DNS query from the command line and look at the hex dump of the packet (especially note the presence and values of the length bytes).

Updated:Add note to pay attention to the length bytes in wireshark dump.