eval { do_something(); }; if(my $error = $@) { cleanup_routine(); die "Error in do_something(): $error"; }