if ( $y[i] <= $y ) { if ( $y < $y[$j] ) { # process ... } } elsif ( $y >= $y[$j] ) { # the same process .. } #### if ( ( $y[$i] - $y ) * ( $y - $y[$j] ) > 0 ) { # process