Catching exceptions with eval 

use English;

sub save_state {
    my($state) = @_;

    eval {
        open my $fh, '>', $state_file or die "...";
        print $fh $state              or die "...";
        close($fh)                    or die "...";
    };
    if($EVAL_ERROR) {
        die "Error saving state: $EVAL_ERROR";
    }
}