sub do_something_with { print "@_\n"; } my @elements = qw( a b c d e f g ); my $n = 2; for my $i ($n-1 .. $#elements) { do_something_with(@elements[($i-($n-1))..$i]); } #### a b c b c d c d e d e f e f g #### a b c d b c d e c d e f d e f g
## a b c b c d c d e d e f e f g ##
## a b c d b c d e c d e f d e f g