in reply to Nested LOOP in HTML::Template

I havent fully analyzed your code, but one problem is when you're pushing onto outer, your anonymous hashref value is attempting to be an array, but hash values cant be arrays, they can be arrayrefs, like this:
push @outer, { 'INNER' => \@inner };
The way that you have it, i believe that @inner will be taken in scalar context which will evaluate to the number of elements in inner.

But, when you then do

@inner = ();
that will also re-initialize the reference in the value pointed to by 'INNER', because thats a ref to @inner.

UPDATE: Forget about this part, i missed the part about resetting $n = 0;
I think that overall, you need to redefine your problem, because you only have 1 loop, and you want to build a 2 level structure. Also, your if ( $n == 1 ) clause will only be true once (on the second iteration), so only 1 thing will get pushed onto @outer.