in reply to Regex to replace consecutive tokens

If you have three or more consecutive commas, then the second one in your regular expression is already consumed by the expression but it is needed as the first one for the next match. So you need a look-ahead assertion instead:

$s=~s/,(?=,)/,0/g;

that matches the comma but does not consume it.

Update: This would create a trailing comma if there was a trailing comma. If you want a 0 instead, use $s=~s/,(?=,|$)/,0/g;.