#! Perl -w use strict; use File::Find; my $fdir='C:'; my @filelist = (); find(\&wanted, $fdir); write_file() if (@filelist); sub write_file() { .... # sub that writes @filelist to a text file } sub wanted { my $thisfile = $File::Find::name; push(@filelist, $thisfile) if ($thisfile =~ m/\.txt/); #for example }