#!perl -p $a=($r='[^{}]')x($n//=500);1while s/($a$r?)($a)/{$1}{$2}/;--$n&&redo;$_="{$_}"