You're assuming that all leaves must be at the same, known depth (5).
If that's a valid assumption, natatime from List::MoreUtils can do the "matrification".
In reply to Re^2: A maybe(?) interesting comp-sci type problem
by ikegami
in thread A maybe(?) interesting comp-sci type problem
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |