#!/usr/bin/perl -w use strict; use File::Find; my @dirs = ('C:/temp'); my %options = (preprocess =>\&newest, wanted=>\&wanted, bydepth=>1); # bydepth didn't work on Windows XP!! find (\%options, @dirs); sub newest { # print "processing $File::Find::dir for ".@_." entries\n"; # takes a list and returns a list of directories/files for # further processing.. my $newest_file; my @files; foreach (@_) { if (!-f) {push @files, $_} # links,directories elsif (/\.txt$/) { $newest_file ||= $_ and next; $newest_file = $_ if (-M > -M $newest_file); } } unshift (@files, $newest_file) if ($newest_file); return(@files); } sub wanted { return if -d; print "$File::Find::name\n"; #only one "newest .txt file!" } __END__ Newest .txt file in each directory... C:/temp/10.txt C:/temp/inline/_Inline/build/_24to32/Comments.txt C:/temp/Martin-GermanSchoolProject/output.txt C:/temp/students/debug_notes.txt