# straightforward approach: track whether this # is the first iteration or not explicitly. my $is_first = 1; my $prev; foreach my $elem ( @array ) { if ( $is_first ) { $is_first = 0; } else { push @result, compute( $elem, $prev ); } $prev = $elem; }