# build a regex matching any of an array of strings $re = qr/@{[join "|", map { quotemeta $_ } sort { length $b <=> length $a } @strings]}/;