open ($outfh, '>selection.txt'); find({wanted => sub { wanted($outfh) } }, @selectedDirs); close $outfh;