$step_size = ($max - $min) / $number_of_steps; my $total = ( F($min) + F($max) ) / 2; foreach ( 1 .. $number_of_steps-1 ) { $total += F( $min + ($step_size * $_) ); } my $area = $total * $step_size;