use strict; use warnings; sub sep { print q{=} x 50, qq{\n}; } sep(); my $dataOffset = tell DATA; my $printIt = 0; while( ) { if( m{begin} ) { $printIt = 1; next; } elsif( m{^end process$} ) { $printIt = 0; next; } else { print if $printIt; } } sep(); seek DATA, $dataOffset, 0; $printIt = 0; while( ) { if( m{^begin} ) { $printIt = 1; next; } elsif( m{^end process$} ) { $printIt = 0; next; } else { print if $printIt; } } sep(); seek DATA, $dataOffset, 0; $printIt = 0; while( ) { if( m{^begin$} ) { $printIt = 1; next; } elsif( m{^end process$} ) { $printIt = 0; next; } else { print if $printIt; } } sep(); __END__ hfkjd process jhk do not begin here because we do not want this line or this start begin *** This is a line we want *** *** So is this *** end process scrap begin the beguine hkl process khfk shoot hooter begin *** Another desired piece of data *** end process more dross #### ================================================== because we do not want this line or this start *** This is a line we want *** *** So is this *** hkl process khfk shoot hooter *** Another desired piece of data *** ================================================== *** This is a line we want *** *** So is this *** hkl process khfk shoot hooter *** Another desired piece of data *** ================================================== *** This is a line we want *** *** So is this *** *** Another desired piece of data *** ==================================================