my @stuff = 0 .. 9; for my $ix ( 0 .. $#stuff ){ my $item = $stuff[$ix]; my $prev = $stuff[$ix-1]; my $next = $stuff[$ix+1]; }