in reply to Recursive tree walk with scoping issues
Instead of letting it change out from under you as you recurse, try writing
while ( my $file = readdir DIR ) { ... [download]