#!/usr/bin/perl
my $s = "(rupert, paul, 23, 8, [{fin, dan, jack},{bill,34,26,49},{84,28}],{34,jack,bon})\n(rupert, paul, 23, 8, [{fin| dan| jack}|{bill|34|26|49}|{84|28}],{34|jack|bon})";
$s =~ s/,(?=(?:\{[^{}]*\}|[^{}])*})|,(?=(?:\[[^\[\]]*\]|[^\[\]])*\])/|/g;
IyEvdXNyL2Jpbi9wZXJsCgpteSAkcyA9ICIocnVwZXJ0LCBwYXVsLCAyMywgOCwgW3tmaW4sIGRhbiwgamFja30se2JpbGwsMzQsMjYsNDl9LHs4NCwyOH1dLHszNCxqYWNrLGJvbn0pXG4ocnVwZXJ0LCBwYXVsLCAyMywgOCwgW3tmaW58IGRhbnwgamFja318e2JpbGx8MzR8MjZ8NDl9fHs4NHwyOH1dLHszNHxqYWNrfGJvbn0pIjsgCiRzID1+IHMvLCg/PSg/Olx7W157fV0qXH18W157fV0pKn0pfCwoPz0oPzpcW1teXFtcXV0qXF18W15cW1xdXSkqXF0pL3wvZzsKcHJpbnQgIiRzXG4iOw==
(rupert, paul, 23, 8, [{fin| dan| jack}|{bill|34|26|49}|{84|28}],{34|jack|bon})
(rupert, paul, 23, 8, [{fin| dan| jack}|{bill|34|26|49}|{84|28}],{34|jack|bon})