open( DLIST, "<", $dirlist ); while ( my $dir = ) { chomp $dir; opendir D, $dir or do { warn "opendir failed on $dir: $!\n"; next; }; ( my $file_list_name = $dir ) =~ tr{/}{%}; open( FLIST, ">", "$log_path/$file_list_name.$today" ) or die "cannot write to $log_path/$file_list_name.$today: $!\n"; for my $file ( sort grep { !-d "$dir/$_" } readdir( D )) { # check for symlink vs. datafile # gather other stat info as needed, # print a nicely formatted line to FLIST } close FLIST; closedir D; } close DLIST;