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