#!/usr/bin/perl -wT # This is an excerpt, though it should work OK. use strict; use IO::Socket; use vars qw($socket); $socket = whoisconnect('whois.networksolutions.com',5); my $fileRead = "test.txt"; open(INF,$fileRead) or die("Could someone tell me where $fileRead is? $! \n"); while (){ my $domain= $_; chomp($domain); if (!$socket->connected()){ # Test connection print "Not Connected, attempting to reconnect. . .\n"; $socket = whoisconnect('whois.networksolutions.com',5); } # If I uncomment the line below, this works beautifully. # $socket = whoisconnect('whois.networksolutions.com',5); $socket->send("$domain\n") or die ("Can't send data $!"); my @answer= <$socket>; foreach(@answer){ print $_; } } close(INF); sub whoisconnect{ my ($domain,$timeout)=@_; my $socket = IO::Socket::INET->new(PeerAddr => $domain, PeerPort => 43, Proto =>'tcp', Type => SOCK_STREAM, Timeout => $timeout, Reuse=>1 ) or die("Couldn't connect: $!\n"); return $socket; }