$_=<>;\x0d {s/(\[)(\d+)(\]B@)(\D+)(\d+)(:[>})])/$4."."x(2+length$5).$1.($2+$5).$3/e&&redo}\x0d {s/(\[)(\d+)(\]B@)(\D+)\1(\d+)\3/$4.","x(4+length$5).$1.($2+$5).$3/e&&redo}\x0d print
Note that non-ascii characters in the above source code will be escaped (such as \x9f).