#!/usr/local/bin/perl -w use Net::hostent; my @ips = qw( 1.2.3.4 5.6.7.8 ); # Use your own IPs my %hosts; foreach my $ip ( @ips ) { my $info = gethost( $ip ); # Returns an object unless( $info ) { warn( "gethost failed for [$ip] : $! $?" ); next; } # ...access other interesting bits of $info if you want... $hosts{$ip} = $info->name(); # Just want the name } # Ta da. The %hosts hash now contains a set of ip => host mappings. foreach my $ip ( keys %hosts ) { print "The hostname of IP address [$ip] is [$hosts{$ip}]\n"; }