Select block of text around matching braces

Hi,
I have several block of text that I need to select, however this text may be spread over several lines and contains the '{' and '}' within it.
For e.g.,

ABC=100{
  DEF = 200
  {
     GHI,
     JKL
  }
}
#2nd Block
123
{
   456{78,910}}
}

I am trying to figure out how to remove the newline characters from the blocks above so that my further processing would be easier.
i.e. I need to get the output something like this,

ABC=100{DEF=200{GHI,JKL}}
123{456{78,910}}}

Am quite new to shell scripting so any help with this is greatly appreciated.

TIA

#!/usr/bin/perl
undef $/;
open FH,"<a.txt";
$str=<FH>;
@arr=split(/#[0-9]+.* Block/,$str);
map {s/[\n ]//g} @arr;
print join "\n",@arr;

Thanks. But would be great if I could explanation of the above code for my understanding.