#!/usr/bin/perl use strict; ( @ARGV == 2 and -f $ARGV[0] ) or die "Usage: $0 input.file domain.to.comment.out\n"; my ( $in_file, $rem_domain ) = @ARGV; open IN, "<", $in_file or die "$in_file: $!"; open OUT, ">", "$in_file.new" or die "$in_file.new: $!"; $/ = "\n}"; # input record separator is line-initial "}" while () { # $_ contains a whole zone block if (/\W$rem_domain\W/) { s/^/#/; # add initial comment to block s/\n/\n#/g; # add comment after each "\n" } print OUT; }