c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @ra = (1, 1, 1, 2, 3, 4, 4, 4, 5, 6, 1, 1, 1); dd \@ra; ;; my $one; $one = pop @ra while $ra[-1] == 1; push @ra, $one if defined $one; dd \@ra; " [1, 1, 1 .. 4, 4, 4, 5, 6, 1, 1, 1] [1, 1, 1 .. 4, 4, 4, 5, 6, 1] #### c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @ra = (1, 1, 1, 2, 3, 4, 4, 4, 5, 6, 1, 1, 1); dd \@ra; ;; my $highest; for my $i (reverse 0 .. $#ra) { last if $ra[$i] != 1; $highest = $i; } $#ra = $highest if defined $highest; dd \@ra; " [1, 1, 1 .. 4, 4, 4, 5, 6, 1, 1, 1] [1, 1, 1 .. 4, 4, 4, 5, 6, 1]