in reply to Match similar words in file name
#! /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"; } }
|
|---|