# open filehandles ... my ($s, $b) = (0,0); my $arc = 'ARCSERVE.NLM'; my @lines = ; foreach my $line (@lines) { if ($line =~ /^\s+$/ and $s) { $b++; last if $b == 2; } $s = 1 if $line =~ /$arc/; print OUTPUT $line if $s and $line !~ /^\s+$/; }