my @a = qw( a b c d e f g ); sub f { my $i = shift; print join(',', @a[$i-2, $i-1, $i]), "\n"; } f(0); f(1); f(2); f(6); #### f,g,a g,a,b a,b,c e,f,g