Perl implementation of ternary search trees.