$ perl -wl use strict; use Test::More tests => 3; use Test::Deep; sub adjSets{ my $min = shift; map { my $start = $_; map { [ @_[ $start .. $start+$_ ] ] } $min-1 .. $#_-$start; } 0 .. $#_ - $min + 1; # <-- one more iteration } my @arr1 = adjSets(2, qw(one two three)); cmp_deeply(\@arr1, [ [ 'one', 'two' ], [ 'one', 'two', 'three' ], [ 'two', 'three' ] ], q{Test 1}); my @arr2 = adjSets(3, qw(one two three four five)); cmp_deeply( \@arr2, [ [ 'one', 'two', 'three' ], [ 'one', 'two', 'three', 'four' ], [ 'one', 'two', 'three', 'four', 'five' ], [ 'two', 'three', 'four' ], [ 'two', 'three', 'four', 'five' ], [ 'three', 'four', 'five' ], ], q{Test 2} ); my @arr3 = adjSets(4, qw(one two three four five six)); cmp_deeply( \@arr3, [ [ 'one', 'two', 'three', 'four' ], [ 'one', 'two', 'three', 'four', 'five' ], [ 'one', 'two', 'three', 'four', 'five', 'six' ], [ 'two', 'three', 'four', 'five' ], [ 'two', 'three', 'four', 'five', 'six' ], [ 'three', 'four', 'five', 'six' ], ], q{Test 2} ); __END__ 1..3 ok 1 - Test 1 ok 2 - Test 2 ok 3 - Test 2 $