I found this lovely snippet of code while fixing* a broken script. I especially love how as a side effect it removes the spaces from $_.
sub Commify
{
s/ //g;
my $delimiter = ',';
my($n,$d) = split /\./,shift,2;
my @a = ();
while($n =~ /\d\d\d\d/)
{
$n =~ s/(\d\d\d)$//;
unshift @a,$1;
}
unshift @a,$n;
$n = join $delimiter,@a;
$n = "$n\.$d" if $d =~ /\d/;
return $n;
}
*The sort of fixing that is done with rm.