in reply to script optmization

None of the solutions given so far would find a word that is divided at the end of a line. Is this as issue? What about capitalization? Embedded in longer words? Plurals, etc?

I doubt that it would help your speed problem, but your 'bylen' is good candidate for a module. In fact, it is an example in the documentation for List::UtilsBy.

Bill