sub min_max_avg { my $ref = shift; my ( $min, $max, $agv, $i ); my ( $current_min, $current_max ); if ( @{$ref} % 2 == 0 ) { ( $min, $max ) = $ref->[0] < $ref->[1] ? ( $ref->[0], $ref->[1] ) : ( $ref->[1], $ref->[0] ); $agv = $ref->[0] + $ref->[1]; $i = 2; } else { $min = $max = $agv = $ref->[0]; $i = 1; } while ( $i < @{$ref} ) { ( $current_min, $current_max ) = $ref->[$i] < $ref->[ $i + 1 ] ? ( $ref->[$i], $ref->[ $i + 1 ] ) : ( $ref->[ $i + 1 ], $ref->[$i] ); $min = $current_min if ( $current_min < $min ); $max = $current_max if ( $current_max > $max ); $agv += $ref->[$i] + $ref->[ $i + 1 ]; $i += 2; } return ( $min, $max, $agv / @{$ref} ); }