in reply to Getting hash key tree

There are several "Finite state machine" implementations on CPAN (Search 'fsm').

This one seems to meet your use case: FSM::Tiny, and appears to be pure perl without dependencies and dependent only on Class::Accessor::Lite, which appears to be free of other dependencies.

                Memory fault   --   brain fried