use strict; use warnings; use Test::More tests => 2; my $file = 'somefile.tmp'; unlink $file; open my $f, '>', $file; close $f; chmod 0000, $file; SKIP: { skip "cannot run under root", 2 unless $<; ok ! eval { somefunc($file); 1; }; ok $@ =~ /cannot open file/; } unlink $file;