#!/usr/bin/perl -n print if (/NAME/../SYNOPSIS/); # then: man ls | this_script.pl #### #!/usr/bin/perl $cmd = shift; open MAN, "man - $cmd |"; while () { $section = $_ if /^[ A-Z]+$/; push @lines, $_ if $section =~ /NAME|DESCRIPTION/; } do_something_else_with(@lines); # perhaps get rid of the page headers/footers