#!/usr/bin/perl -w use strict; use Template; my $folks = [ { name => 'bob', fruit =>'kiwi', friends => [qw/ sally jessie raphael/], }, { name => 'sally', fruit => 'kumquat', friends =>[], }, { name => 'misery', fruit => 'company', friends =>[qw/ avarice sloth /], }, { name => 'batman', fruit => 'robin', friends =>[qw/ catwoman /], }, ]; #and you pass that in to a template as 'folks', you can have a loop like this: my $template = Template->new(); my $output; $template->process(\*DATA, {folks=>$folks}, \$output) || die $template->error; print $output; __DATA__ [%- FOREACH person = folks %] ====================== [%- person.name %] likes [% person.fruit %] [%- FOREACH friend = person.friends -%] [%- IF loop.first %] [% person.name %] is a friend of:[% END -%] [%- IF loop.last && person.friends.size > 1 %] and[% END %] [% friend %][% IF not loop.last and person.friends.size > 2 %],[% END -%] [%- END -%] [%- IF loop.last %] ====================== [%- END -%] [%- END %]