while () { chomp; print commify($_), "\n"; } # From _The Perl Cookbook_, recipe 2.17 sub commify { my $text = reverse $_[0]; $text =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/g; return scalar reverse $text; } __DATA__ 195000 42000 2100 #### 195,000 42,000 2,100