#!/usr/bin/perl $mark_in = "
"; $mark_out = ""; sub marked_section { @marked = ("$_[0]$mark_in\n"); while ($line = <>) { push @marked, $line; last if $line =~ /$mark_out/; } print $marked[0]; for ($from = 1; $marked[$from] =~ /^\s*$/; $from++) # $from: at 1st to {} # print for ($to = $#marked - 1; $marked[$to] =~ /^\s*$/; $to--)# $to: last to pnt {} for ( ; $from <= $to; $from++) { print $marked[$from]; } print $marked[$#marked]; while ($line = <>) { last if $line !~ /^\s*$/; } if ($line =~ /(.*)$mark_in\s*/) { marked_section($1); } else { print $line; } } while ($line = <>) { # added $1 to pick up leading text. $2 now used to be $1 if ($line =~ m#(.*)