Text::Prefix::XS implements something of an trie algorithm for matching (and extracting) prefixes from text strings. WWW: https://metacpan.org/release/Text-Prefix-XS