This is a well-known problem with depply-recursive data structures. The code in perl to free such structures is recursive, and after a cetain depth it blows the processor stack. The workarounds are to increase the stack size with ulimit, or free the struture using perl-level recursion (which doesn't use the stack).