You familiar with recursion?

All you need is a recursive function which looks for separators: If it finds none, you've hit the base case (an individual panel) and you can store it away. Otherwise,...