Can you rely on $@? 

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