Text::Prefix::XS implements something of an trie algorithm for matching (and extracting) prefixes from text strings. WWW: http://search.cpan.org/dist/Text-Prefix-XS/