in reply to recursive algorithm for nested data structures
That looks like Lisp. Perhaps Data::SExpression would be useful?