my $text = 12345678.9; commify($text); print "\n |$text|\n"; # after Perl Cookbook recipe 2.17 sub commify { my $text = reverse $text; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; print "In the sub: " . reverse $text . "\n"; }