if( $_ eq "--end foo--\n"){ # . . . } #### my $interesting_bit; { # maybe open here . . . local $/ = '--start foo--' . "\n"; $interesting_bit = ; local $/ = '--end foo--' . "\n"; $interesting_bit = ; # . . . and close here } #### my $interesting_bit; { # maybe open here . . . local $_; while () { if ($_ eq "--start foo--\n" .. $_ eq "--end foo--\n" ) { $interesting_bit .= $_; } elsif ( $interesting_bit ) { last } } # . . . and close }