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