in reply to AoH refs for setting HTML::Template loops

when does $selbranch become an array? a reference?
The code $selbranch->[$i]{'value'}=something will, assuming $selbranch is currently undefined, create a new anonymous array, make $selbranch a reference to it, then create a new anonymous hash, and make $selbranch->[$i] a reference to it, then store the value in the 'value' slot of the hash. So it looks like you're doing the right thing. I'd recommend doing
use Data::Dumper; print Dumper($branch); print Dumper($selbranch);
to see what data structures you've actually got.