Well, you need to declare those variables. RFC: Tutorial: use strict; now what!? Might help you a bit.
In reply to Re^7: Tree depth by moritz in thread Tree depth by katarinahm