The CGI::Carp module might come in handy here. Put the following near the top to trap die exceptions:
use CGI::Carp qw(fatalsToBrowser);
I wouldn't run this in production code, as it could give out information a malicious cracker might be able to exploit.
Update: Okay, it might not. Win some, lose others.