Exception handling 

my $error = do {
    local($@);
    eval { do_something() };
    $@;
}
if($error) {
    cleanup();
    die "Failed in do_something: $error";
}