I used to have that same problem, so what I did was create a convention for myself where $dir is the directory, $file is the filename without directory and $path is the two together and make sure that having assigned $path = "$dir/$file", that $dir and $file do not appear further down the same routine (only $path and $dh, the directory handle assigned to $dir)