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


in reply to Longest String Matching

Reverse the string you're searching, and add the items you're searching for (reversed too) to a Tree::Trie, which is optimized for fast prefix searches. You're not using a has but it's still O(1).