use strict; use warnings; use Template; #you would normally take this from a file my $template = join "", ; #some sample data my %data = ( title => "My Albums", albums => [ { artist=>"Some Musician", songs=> [ "Some Song", "Some Other Song", ] }, { artist=>"DocMarten", songs=> [ "The Doc goes wild", "Heavy Shoes", ] } ] ); #create template object and execute template my $tt = Template->new(); $tt->process (\$template, \%data, "myfile.html"); __DATA__ [% title %] [% FOR album = albums %]

[% album.artist %]

[% FOR song = album.songs %]

[% song %]

[% END %] [% END %] #### My Albums

Some Musician

Some Song

Some Other Song

DocMarten

The Doc goes wild

Heavy Shoes