# Assuming $path contains the full pathname of the file/directory if (-d $path) { # It's an existing directory } elsif (-f $path) { # It's an existing file }