chdir $toppath or die "can't cd to $toppath: $!"; open( FIND, "find . -type d |" ) or die "can't run find: $!"; while ( my $d = ) { chomp $d; unless ( opendir( D, $d )) { warn "$toppath/$d: open failed: $!\n"; next; } while ( my $f = readdir( D )) { next if ( -d "$d/$f" ); # outer while loop will handle all dirs # do what needs to be done with data files } # anything else we need to do while in this directory } close FIND;