$_='~1~,,~234~,7,~,,~,8,~223~,,9'; s/(~\d\d*~)(,,)/\1,~~,/g; ~1~,~~,~234~,7,~,,~,8,~223~,~~,9