my $bigRegex; $bigRegex = join '|', map { "\b$_\b" } sort { length $b <=> length $a } @molecules;