use strict; use warnings; my %exceptions = (cust1 => \&cust1Handler, cust2 => \&cust2Handler); eval { die "cust1\n"; }; if ($@) { chomp $@; die "Unhandled exception: $@\n" unless exists $exceptions{$@}; $exceptions{$@}->(); } else { print "Success\n"; } sub cust1Handler { print "Turned to custard - 1\n"; } sub cust2Handler { print "Turned to custard - 2\n"; }