$pattern = join '|', map quotemeta, sort { length($b) <=> length($a) } keys %map;