$dirname = 'x'; system("[ -d '$dirname' ]"); # $? >> 8 (or the return value from system >> 8) is 0 on success if ($? >> 8) { print "does not exist"; } else { print "exists"; } print "\n";