Catching Exceptions with eval 

use English;

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

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