my $dir_list = [ { dir => 'foo', dir_row => [ { file_row => [ { filename => 'foo0.pic' }, { filename => 'foo1.pic' }, { filename => 'foo2.pic' }, { filename => 'foo3.pic' }, { filename => 'foo4.pic' } ] }, # for file_row # second row (next batch of files of 5) { file_row => [ { filename => 'foo5.pic' }, { filename => 'foo6.pic' }, { filename => 'foo7.pic' }, { filename => 'foo8.pic' }, { filename => 'foo9.pic' } ] }, # for file_row ] # for dir_row }, { dir => 'bar', dir_row => [ { file_row => [ { filename => 'bar0.pic' }, { filename => 'bar1.pic' }, { filename => 'bar2.pic' }, { filename => 'bar3.pic' }, { filename => 'bar4.pic' } ] } # for file_row ] # for dir_row } ];