#!/usr/bin/perl use strict; my $inputfile = shift; my $withinBlock = 0; open (IN, "<$inputfile") || die "could not open $inputfile\n"; while () { if (/head/) { $withinBlock = 1; print $_; if (/tail/) { $withinBlock = 0; print "\n"; } } if ($withinBlock) { print $_; if (/tail/) { $withinBlock = 0; print "\n"; } } } close (IN);