sub exception (;$) { my $wanted_exception = shift; return unless $@; return 1 unless defined $wanted_exception; return ref($@) && $@->isa( $wanted_exception ) }; #### eval { $coderef->() }; if ( exception 'IOException' ) { ... handle IOException ... } elsif ( exception 'OtherException' ) { ... handle OtherException ... } elsif ( exception ) { ... handle all other exceptions ... } else { ... we lived ... };