my $sep = ','; my $number = '12345678.27'; print MakeThousands($number), "\n"; sub MakeThousands { local $_ = reverse(shift()); s/(\d{3})(?=\d)(?!\d*\.)/$1$sep/go; return scalar(reverse()); } #### Benchmark: timing 5000000 iterations of MakeThousands, Thousandformat... MakeThousands: -1 wallclock secs ( 0.06 usr + 0.00 sys = 0.06 CPU) @ 83333333.33/s (n=5000000) Thousandformat: 1 wallclock secs ( 0.12 usr + 0.00 sys = 0.12 CPU) @ 41666666.67/s (n=5000000)