Вот способ разделить проблему на несколько отдельных компонентов:
use strict;
use warnings;
sub consec_subseq_leading {
# (1, 2, 3) ==> ( [1], [1, 2], [1, 2, 3] )
return map [ @_[0 .. $_] ], 0 .. $#_;
}
sub consec_subseq {
# (1, 2, 3) ==> ( F(1, 2, 3), F(2, 3), F(3) )
# where F = consec_subseq_leading
my $j = $#_;
return map consec_subseq_leading( @_[$_ .. $j] ), 0 .. $j;
}
my @cs = consec_subseq(0 .. 4);
print "@$_\n" for @cs;