$number =~ s/(\d+)(\.\d+)?/bea_int($1).$2/eg; sub bea_int { my $kk = $_[0]; $kk =~ s/(\d)(?=(\d{3})+(\D|$))/$1\,/g; return $kk; }