my @files; #reading directory opendir(MYDIR, "data"); my @contents = readdir MYDIR; #going through all files in directory foreach my $file(@contents) { #if file is a .txt if($file =~ m/\.txt$/) { #store file to array push(@files, $file); } } #closing directory handle closedir MYDIR;