http://www.perlmonks.org?node_id=1029146


in reply to Require input reading files recursively in perl

General disclaimer: use strict/warnings.

Using a global filehandle (or in general any global variable that can be modified) with recursion is a *bad* idea. Instead use lexcials:
opendir(my $SCR , $dir) or die "Can't open $dir: $!"; while( defined (my $file = readdir $SCR) )
Don't forget to closedir when done.