my @files; sub search { push @files, $_ if -f; } sub handle_directory { @files = sort { lc($a) cmp lc($b) } @files; # do something with @files print "@files\n"; # get ready for the next directory undef @files; } File::Find::find( { wanted => \&search, bydepth => 1, postprocess => \&handle_directory }, $directory );