use constant NUM_ELEMENTS => 15; # Get the starting_array from somewhere my @starting_array = populate_somehow_with_data(); my $start_index = 0; while ($start_index <= $#starting_array) { my $end_index = $start_index + NUM_ELEMENTS - 1; $end_index = $#starting_array if $end_index > $#starting_array; my @array_slice = @starting_array[$start_index .. $end_index; $start_index += NUM_ELEMENTS; # use @array_slice here to do what you need to do. }