my $delta = 0.01; # choose some sensible value (defines range) for my $i (0 .. $#array_of_x_values) { my ($x, $y) = ($array_of_x_values[$i], $array_of_y_values[$i]); my $y_trend = $intercept + ($x * $slope); my $resid = $y - $y_trend; if ($resid > -$delta and $resid < $delta) { # points are "on" (i.e. within some small range around) trend line # ... } else { if ($resid > 0) { # points are above the trend line # ... } else { # points are below the trend line # ... } } }