# untested foreach my $dir (@subdirs) { # if you have .. you have also . next if ($dir eq "."); next if ($dir eq ".."); my @files = File::Find::Rule->file()->name('*.*')->in($dir); # compose a filename: # you probably need a path not just a name; you have not cd to the inside directory # many module can hadle this for you, but you can deal with a relative path too my $outputname = "./$dir/List.txt"; # open ALWAYS a lexical FH using the 3 args form.. open my $lexical_filehandle, '>', $outputname or die "Cannot write to $outputname"; # print each filename to the listfile print $lexical_filehandle "$_\n" for @files; close $lexical_filehandle; }#next dir will be processed #### find . -type d -maxdepth 1 | perl -lne "system qq(ls $_ > ./$_/_list.txt)"