in reply to query dns by hostname
I think you are misunderstanding what gethostbyname() does. gethostbyname allows you to resolve a DNS (or /etc/hosts entry) to an IP address. It does not allow you to do wildcard searches on a partial domain name.
In Section
Seekers of Perl Wisdom