eval { your code with die here ... }; if ($@) { # print to web browser print CGI::header ...; print "Error occured: $@"; die; }