while( s/(\d)(\d\d\d)(?!d)/$1,$2/ ) { 1; ## do nothing, let the regex go until it no longer matches }