#!perl -lp my%h;while(/@{['\D+(\d+)'x4]}/g){for$;($1..$1+$3-1){$h{1,$_}.=$&for$2..$2+$4-1}}$_=join$",map{$_,($t=s//.*/gr)+map/$t/,%h}ab,ac,bc,abc