#!/usr/bin/perl -w use strict; # variable to hold the previous header my($header); foreach (<>) { if (/^Header Line (\S+)$/) { die "Error - header repeated in line $.\n" if ($header && $header eq $1); $header = $1; next; } if (/^[\w\*\/]{3}-[\w\*\/]{3}/) { # do whatever processing on the line print "Got a matching line...\n"; } }