# method one $SIG{PIPE} = sub { $SERVER_DISCONNECT = 1; }; # # when printing to socket, check $SERVER_DISCONNECT # and handle if ($SERVER_DISCONNECT == 1) # method two (Posix systems only) $SIG{PIPE} = 'IGNORE'; use Errno ':POSIX'; # other code here unless (print SOCKET "$data") { if ($! == EPIPE) { # pipe error, attempt reconnection to server } else { # real error } }