The distance is rounded to two decimals and PERL is not great at rounding, but I chose to do it this way:
$distance = substr($distance+("0." . "0" x 2 . "5"),0, 2+length(int($distance))+1);
Which seems to work fine 99.9% of the time, but gets a little widgey with more than 10 repeating decimals.