in reply to foreach vs. while inside a directory tranversing subroutine

it might be instructive to bracket the traverse_file in the first version with print statements and see what you get, e.g., replace the inner
traverse_file($_);
with
print STDERR "> $_\n"; exit 0 if ++$count > 100; traverse_file($_); print STDERR "<\n";
with a suitable our $count=0 at top level somewhere.