http://www.perlmonks.org?node_id=221271


in reply to Re: Re: Re: count sort & output
in thread count sort & output

Your code has a potential subtle bug. You would have to sort your strings by length and build your regular expression with the longest ones first.

You are of course right about the bug lurking in that snippet (sorting the strings in reverse order will fix this). My point was to let the regex engine do its work instead of the nested loop. That, and the suggestion to store intermediate results that would make for slowness.