my $g = ","; # Could be ' ' or '.' in other locales my $n = 1234567890; $n = reverse $n; $n =~ s/(\d{3})/\1$g/g; $n = reverse $n;