... my $file_mask = qr{\.txt$}; ... my @files = grep { m{$file_mask} and -f and not -l } readdir DIR; ...