I doubt this is working code, for a couple of reasons:
- insert, collect_nodes and search subroutines have incorrect parameter assigments (all but first parameter are uninitialised)
- search is nondeterministic (hash keys have random iteration order since Perl 5.18 and unpredictable order in earlier versions)
- search will probably die if you ever get to the "return push(...)" branch