#!/usr/bin/perl use strict; use warnings; while (my $line = ) { process_record($line) if $line =~ /START/; } sub process_record { my ($line) = @_; my @lines; my $found; push @lines, $line; #the "START" line while ( $line = , $line !~ /END/) { $found = 1 if $line =~ /def/; push @lines, $line; } push @lines, $line; #the "END" line print @lines unless $found; return; } =prints START xyz abc END =cut __DATA__ START abc def ghi END junk more junk START xyz abc END