while (defined $client_socket->recv($data, 1024)) { ### always true even if the remote end has crashed print "received data: $data\n"; }