my @files = glob("*.jpg"); my $width = 3; my @images = (); for my $i (0..$#files) {  if ($i % $width == 0) { # new row, append to dimension X    push (@images, { schleifeY => [ { inhalt => $files[$i] } ] } );  }  else { # new column, append to dimension Y    push (@{ $images[-1]->{schleifeY} }, { inhalt => $files[$i] } );  } # else } # for $template->param(schleifeX => \@images);