open (MAN, "/usr/bin/man ssh |"); my $printing_on = 0; # If true, print what you see while () { s/^\s+//g; # if you like; could be omitted. if ($_ eq "NAME\n") # constant string; no regexp needed { $printing_on = 1; } elsif ($_ eq "SYNOPSIS\n") { exit; # we're done } print if $printing_on; }