#!/usr/bin/perl -w use strict; my $do_i_chomp?; # off by default while(<>){ # read from STDIN $do_i_chomp? && chomp; # chomp if you should m/^DESCRIPTION$/ && do{ !$do_i_chomp?; # flip chomping on print; # print the DESCRIPTION line }; print; # print the line m/^ENDDESCRIPTION$/ && do{ print "\n$_"; # print newline, then the ENDDESCRIPTION line !$do_i_chomp?; # flip chomping off }; }