Well, if the problem is a broken pipe, why not install a
signal handler to trap that error (in fact, why not install
signal handlers for all the errors you might run into?). That way, if the program traps an error, it can execute
any "cleanup code" that needs to be done before wiping the pid file and shutting down.
I believe the syntax for a signal handler involves manipulating the "pseudo" hash %SIG
and looks something like this.
$SIG{PIPE} = sub { #handle error }
There's also a sigtrap module, you might want to check that out