foreach (keys(%servers)) { print "Connecting to $_ :: $servers{$_}: "; my $socket; $socket = IO::Socket::INET->new( PeerAddr => $_, PeerPort => $servers{$_}, Proto => "tcp", Reuse => 1, Type => SOCK_STREAM); if (! defined ($socket)) { print "$@\n"; next; } print "Connected\n"; close $socket; $socket->DESTROY; print "..\n"; } #### Connecting to 24.164.137.84 :: 3456: IO::Socket::INET: connect: Connection refused Connecting to 62.163.22.155 :: 4200: Connected .. (hangs here) Connecting to 80.117.254.113 :: 8888: IO::Socket::INET: connect: Connection refused Connecting to 62.226.24.21 :: 8888: IO::Socket::INET: connect: Connection refused (hangs here) Connecting to 80.134.24.185 :: 8888: IO::Socket::INET: connect: Connection refused Connecting to 217.84.215.47 :: 7777: IO::Socket::INET: connect: Connection refused Connecting to 80.133.122.25 :: 7777: IO::Socket::INET: connect: Connection refused Connecting to 213.84.39.165 :: 4567: IO::Socket::INET: connect: Connection refused Connecting to 24.156.72.65 :: 513: IO::Socket::INET: connect: Connection refused (hangs here)