#!/usr/bin/perl use strict; use warnings; { open my $fh, '<', 'somefile' or die "Opening somefile for reading: $!"; sub seeky { seek $fh, 0, 0 } } while () { chomp; my $line = $.; warn "Pre match: Line $. == $line\n"; next if /match/; seeky(); warn "Postmatch: Line $. != $line\n"; } __END__ foo match bar baz match bot