opendir DIR, '.' or die "Error: $!"; my @files = grep { /\.txt$/ } readdir DIR;