in reply to Recursive tree walk with scoping issues

In addition to the scoping issue with file handles that Zaxo caught, you have a runaway scoping problem with $_.

Instead of letting it change out from under you as you recurse, try writing

while ( my $file = readdir DIR ) { ...
and eliminate your use of $_ altogether.