sub commify { local $_ = shift; 1 while s/^(-?\d+)(\d{3})/$1,$2/; return $_; }
$n = 23659019423.2331; print "GOT: ", commify($n), "\n";
GOT: 23,659,019,423.2331
You can't just:
s/^(-?\d+)(\d{3})/$1,$2/g;
because you have to put the comma in and then recalculate your position.