in reply to next if regex matches

I think you are using character classes for alternation and hence getting the wrong result (ie [\.txt|\.log] this is the same as [.txt|log] in that it would match if any of the characters inside the character class that exist at that position, which in this case is anywhere in the string.)

Both of these should work:

next unless ($path =~ /\.(?:txt|log)$/); next if ( $path !~ /\.(?:txt|log)$/;
update: I added the $ to your original regex to match the end of the line (or before newline at the end), as I am assuming that these are the extensions to the files and hence will only appear at the very end of the string (you don't want a file like foo.txt.tmp matching)

-enlil