while(<>) { if (my $r = /^Services/ .. /^Users/ ) { next if $_ =~ /^Services/; print $_; last if $r =~ /E0$/; } }