I have a string containing curly brackets and I want to replace any character A, which is not contained in a pair of opening and closing brackets, by another character B. So
ABCDACD{ACDA}ABCD
should be replaced by
BBCDBCD{ACDA}BBCD
How can I do this with a regex (e.g. in Perl)? Brackets are not nested, but a solution working also for the nested case would be better.
EDIT: Changed wording