use Net::Ping; my @protocols = qw(icmp tcp); my @host_array = ("www.google.com", "irc.webchat.org", "64.177.244.76"); foreach my $proto (@protocols) { my $p = Net::Ping->new($proto); foreach my $host (@host_array) { print "With $proto, $host does "; print "NOT " unless $p->ping($host); print "respond\n"; } $p->close(); }