Text::Prefix::XS implements something of an trie algorithm for matching (and extracting) prefixes from text strings.