# note that this alters @array my $prev = shift @array; foreach my $elem ( @array ) { push @result, compute( $elem, $prev ); $prev = $elem; }