my $match_balanced_braces = qr/(\{(?:[^\{\}]++|(?-1))*\})/;

local $/;
while (<>) {
    my @matches = $_ =~ /(\btypedef\s+struct(\s+\w*)?\s*${match_balanced_braces}[^;]+;)/xg;
    my $count = 0;
    foreach my $match (@matches) {
	if (!($count % 3)) {
	    $match =~ s/${match_balanced_braces}/ \{\} /xg;
	    $match =~ s/\s+/ /g;
	    print("$match\n");
	}
	$count++;
    }
}
