sub loopDir { my @files; local ($dir) = @_; chdir $dir or die "Cannot chdir to $dir\n"; local(*DIR); opendir DIR, '.'; while ($f=readdir(DIR)) { next if $f =~ /^\./; push @files, $dir . '/' . $f if $f =~ /.*\.xml$/; if (-d $f) { # push the subdirectory's files onto @files push @files, &loopDir($f); } } closedir(DIR); chdir(".."); # return the list of files return @files; }