in reply to Checking for NPH client connection

I believe that $SIG{PIPE} will indicate if the browser has disconnected... perhaps something like this would work:
$SIG{PIPE} = sub { exit; }
...or, if you have a sub already which performs the cleanup, perhaps called "cleanup()"...
$SIG{PIPE} = \&cleanup;

Hot Pastrami