my $phase = 0; my $start = ' ) { if ( $phase == 0 ) { if ( /$start(.*)$/ ) { $phase++; $_ = $1; } else { next; } } if ( $phase == 1 ) { if ( /(.*)$finish/ ) { $content .= $1; last; } $content .= $_; } }