$amount = reverse $amount; $amount =~ s/(\d{3})/$1,/g; $amount = reverse $amount;