Do a
` with ls or dir, then parse the output. Those 2 tools will use a faster/lower overhead OS call than perl would be using. You are also touching the disk repeatedly and unnecessarily by doing
-f $ObjectName and
-d $ObjectName many times in the logic tree instead of doing them
once and caching the result to a scalar before the logic tree.