connected will not work. It is actually just an indication of whether you locally closed the socket. Whatever the remote peer is shutdown normally or abnormally, connected always tells that it is still connected, unless you locally shut it.
The way I always use is to check whether I receive any zero length packet. If yes, I know the connection is gone.
For example:
while (1) {
my $req;
$socket->recv($req, 1000);
last if ($req eq "");
...
}