in reply to Maintain TCP client connection to server?

If you are writing to a disconnected stream socket then you will get a SIGPIPE which you can be trapped like:

$SIG{PIPE} = sub { print "WHoah got disconnected" };
You can put any code you want to reconnect and retry the send.

/J\