#!/usr/bin/perl -W use strict; use warnings; sub listText { my $myDir = $_[0]; my @fileList; my $wanted2 = sub { my $filePath = $File::Find::name; if ($filePath =~ /txt/) { push(@fileList, $filePath); } }; find({wanted => $wanted2, no_chdir => 1}, ($myDir)); return @fileList; }