#!/usr/bin/perl my @a = (99999, 34,67,976,432,99999); my $length = scalar(@a); for ($counter = 0; $counter<=$length; $counter++){ my $max = max(-3 + $counter, 1); print "$max\n"; my $second_counter = -($length - $counter); print "$second_counter\n"; my @worker = splice @a, $max, $second_counter; print "@worker\n"; }