use warnings; use strict; my %h = ( -r => sub { -r shift }, -w => sub { -w shift }, ); my $testDir = '/tmp/'; checkDir( $testDir, '-w' ); checkDir( $testDir, '-r' ); sub checkDir { my ( $dir, $perm ) = @_; die '???' unless exists $h{$perm}; if ( $h{$perm}($dir) ) { print "Can $perm $dir\n"; } else { print "Can not $perm $dir\n"; } }