Net::SSLeay::set_fd($ssl, fileno($socket)); my $res = Net::SSLeay::connect($ssl) and Net::SSLeay::die_if_ssl_error("ssl connect"); if($res < 0){ # Here the connect failed because the exchange is not complete; # continue to select on this socket and retry every time the # socket selects true until it succeeds. return; } else { # Here the connect is complete. This is where to but the code # that changes the "select" handler for the socket for the next # phase (writing the data). }