my $open_ok = open my $fh, $mode, $filename; if (not $open_ok) { # custom error handling here }