zone "10.in-addr.arpa" { type forward; forwarders { 10.1.2.3; 10.1.2.4; 10.1.2.5; }; }; #### my $comment = 0; my $block = 0; while () { /^zone\s+"$targetdomain"/ and $comment++; if($comment) { $block += () = /(\{)/g; # add the number of { matches to $block s!^!// ! if $comment && $block; $block -= () = /(\})/g; # substract the number of } matches $comment = 0 unless $block; } print; }