cat <<'EOF' |
perl -wpe '1 while s/(\d+)(\d\d\d)/$1,$2/;'
This is accomplished by splitting the string of digits into 2 groups, the right-hand group with 3 digits, the left-hand group with whatever remains, but at least one digit. Then everything is replaced by the 2 groups, separated by a comma. This continues until the substitution fails. The options "wpe" are for error listing, enclose the statement inside a loop with an automatic print, and take the next argument as the perl "program" (see command perldoc perlrun for details).
Best wishes ... cheers, drl