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