my $max = 10_000; $distance -= $radius; $distance = 0 if $distance < 0; $distance *= $max/($max-$radius)