use Errno ; # for ECONNREFUSED use IO::Socket::INET ; # portions copies from the IO::Socket::INET man page: $sock = IO::Socket::INET->new(PeerAddr => 'www.perl.org', PeerPort => 'http(80)', Proto => 'tcp'); if( $sock == undef && $! == ECONNREFUSED ) { # server not operating? }