my $fh; open $fh, "<", "/etc/shadow" or $fh = undef; if ($fh) { # do stuff } #### if (open my $fh, "<", "/etc/shadow") { # do stuff. close $fh; }