use strict; use warnings; my $input_dir = 'D:/Perl/Paul/'; my $file_extension = '.txt'; sub get_files { my $input = shift; unless(opendir(INPUTDIR, $input)) { die " Unable to open directory \n $input \n" } my @filelist = readdir(INPUTDIR); closedir(INPUTDIR); @filelist = grep(/$file_extension/i, @filelist); return @filelist; } sub main { my @files = get_files($input_dir); foreach my $file (@files){ print "$file \n"; } } main();