opendir(D, $dir) or die "unable to read $dir: $!" while (defined(my $leaf = readdir(D))) { my $path = "$dir/$leaf"; # perhaps use File::Spec here ... some_function($path); # often passing $leaf here is a mistake ... } closedir(D);