perl -le '$_="[987]ABC[GHI]XYZ[dfg]"; print "$_" for split/(?!\w+\])|\[|]/,$_'