Implementation of a ternary search tree in perl