while (++$num_tries < 10) { if( $lock = IO::Socket::INET->new(Proto => "tcp", PeerAddr => $server, PeerPort => $port) ) { $lock->autoflush(1); last; } sleep 1; # wait a second, don't tie up the CPU }