# extract_min_uniq_2.pl 15jun15waw use warnings; use strict; use LeadingDistinct; use Data::Dump qw(dd); use constant DEBUGGING => 0; use constant { PR_DB1 => 1 && DEBUGGING, PR_DB2 => 1 && DEBUGGING, PR_DB3 => 1 && DEBUGGING, }; my @tokens = qw/report_time report_day reset read/; my %min_distinct = LeadingDistinct::extract(@tokens); dd \%min_distinct if PR_DB1; for my $k (keys %min_distinct) { $min_distinct{$k} = max_optional_rx($k, $min_distinct{$k}); } dd \%min_distinct if PR_DB2; my ($find) = map qr{ (?) { next unless m{ \A ($find) }xms; print "$1 \n"; } # subroutines ###################################################### sub max_optional_rx { my ($whole, # full word $unique, # distinctive characters at start of word ) = @_; my @tail = split //, substr $whole, length $unique; my $opt_tail = optional_tail(@tail); return qr{ \Q$unique\E $opt_tail }xms; } sub optional_tail { my $rx = ''; return $rx unless @_; $rx = quotemeta shift @_; for my $c (@_) { $c = quotemeta $c; $rx .= " (?: $c)?"; } $rx = qr{ $rx }xms; return "$rx?"; } __DATA__ report_t 14:09:33 PDT report_d Fri Jun 12 2015 report (should not show up) res Resetting the time report_time 00:00:00 rea foo.bar Info: reading file foo.bar