my $path = "/path/to/file_or_dir"; if (-f $path) { # this is a file } if (-d $path) { # this is a directory }