use Errno; if (open $fh, "<", "foo/bar/baz") { ... } elsif ($!{EPERM}) { print "no go!\n"; } else { print "error opening foo/bar/baz: $!"; }