Code: Perl
use strict;
use warnings;

my @array = ( 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 1, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9 );

my $subset_start_idx = 0;
for ( my $i = 0 ; $i <= $#array ; $i++ ) {
    my $next_idx = $i + 1;
    if ( ( $next_idx <= $#array && $array[$next_idx] < $array[$i] ) || $next_idx == $#array ) {
        printf( '(%s) Start = %s End = %s%s', join( ',', @array[ $subset_start_idx .. $i ] ), $subset_start_idx, $i, "\n" );
        $subset_start_idx = $next_idx;
    }
}

Output:
Code:
(1,2,3,4,5,6) Start = 0 End = 5
(1,2,3,4) Start = 6 End = 9
(1,2) Start = 10 End = 11
(1,2,3,4,5,6,7,8) Start = 12 End = 19

Last edited by pradeep; 25Nov2011 at 11:20.. Reason: Bug fix