note
Matts
Are you sure this isn't the problem:
<code>
if ($config{debug}) { print "pos[depth]: " . ${$pos[$depth]} . "\n" }
</code>
This tries to treat <code>$pos[$depth]</code> as a scalar reference and dereference it. But that array entry is just a plain scalar, so you don't need to dereference it at all.
<p>
I'm guessing though, since I didn't take the time to run your code.
222652
222652