in reply to if (-d$_) failes because of white space

Your problem may be that your $_ does NOT contain full path to the item in question.

Change your code to die() if not a dir and tell you what it tested for.

use Cwd; foreach(@dir) { if (-d$_) { print $_," is a directory.\n"; } else { die("Not a dir '$_', current working directory is: ". cwd()) +; } }