in reply to Match similar words in file name

The common trick is to sort the words by length descending. The longer matches will then be tried first.
#! /usr/bin/perl use warnings; use strict; use feature qw{ say }; my @files = qw( 20220401_note.txt 20200101_no_match.txt 20220303_page.txt 20220101_page_with_blanks.txt 20220111_page_blanks.txt ); my @get = qw( note page page_with_blanks page_blanks ); my $match = join '|', sort { length $b <=> length $a } map quotemeta, @get; for my $file (@files) { if (my ($date, $name) = $file =~ /(202[0-9]{5})_($match)/) { say "D:$date - N:$name"; } }

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]