Help for this page
$string =~ s/([^\s\.\]\[]+)/exists($tokens_to_match{lc $1}) ? $tokens_to_match{lc + $1} : $1/ge;
my $str = join '|', sort { length $b <=> length $a || $a cmp $b } keys %tokens_to_match; ... : $2 ) /gei;