in reply to Question: File name pattern match using Grep function

# Finds a file called 1txt (WHY)

Because "\.txt" becomes just '.txt', which when it is reinterpolated here:

my @files =grep(/$file_mask$/,readdir(DIR));

Is taken to mean 'any char' followed by 'txt$'. To avoid the problem, use

my @files =grep(/\Q$file_mask\E$/,readdir(DIR));

To prevent characters within $file_mask being treated as meta characters.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."