sub probe { use integer; my( $aref, $lo, $hi, $limit, $istep ) = @_; my $step = ( $hi - $lo ) / $istep; { my $i = $lo; $i += $step while $i <= $hi and $aref->[ $i ] <= $limit; if( $i >= $hi ) { if( $aref->[ $hi ] == $limit ) { --$hi while $aref->[ $hi - 1 ] == $limit; return $hi; } $step /= 2; } else { $limit = $aref->[ $i ]; $lo = $hi - $step; ## Update: Swapped the order of this line and the next $hi = $i; $step = int( ( $hi - $lo ) / $istep ); # $istep was wrongly '10' } redo; } }