my $file = "does-not-exist"; while () { eval { open my $fh, "<", $file or warn "Couldn't open '$file': $!" and exit; }; print STDERR "ERROR: $@" if $@; }