in reply to directory or file?

To test if is a directory, use the -d file test operator. For example, this code would print "foo" if /bar was a directory.
print "foo\n" if (-d "/bar");
To test if something is a file, use the -f file test operator.