$_ = join'', <DATA>;
print m/^DESCRIPTION(.*?)\n\n/ms;;
__DATA__
NAME
perldoc - Look up Perl documentation in pod format.
SYNOPSIS
perldoc [-h] [-v] [-t] [-u] [-m] [-l] [-F] [-X]
PageName|ModuleName|ProgramName
perldoc -f BuiltinFunction
perldoc -q FAQ Keyword
DESCRIPTION
*perldoc* looks up a piece of documentation in .pod
format that is embedded in the perl installation tree
or in a perl script, and displays it via `pod2man |
nroff -man | $PAGER'. (In addition, if running under
HP-UX, `col -x' will be used.) This is primarily used
for the documentation for the perl library modules.
Your system may also have man pages installed for those
modules, in which case you can probably just use the
man(1) command.
OPTIONS
-h help
Prints out a brief help message.
We get away with the one liner because in list context a regexp returns a list of what it matched so effectively we are dining a m/(this)/; print $1. We need the /m and /s modifiers. For details on why see perlman:perlre To get the entire output of the man command into a var like $_ the easiset way is to use backtics like this $_ = `man $manpage`;. Don't let just anyone supply the input value to $manpage as nasty input can do nasty things in bactics. A value like '; rm -rf *;' might be suboptimal.
A short program to do this might be:
#!/usr/bin/perl -w
use strict;
print "Which manpage? ";
chomp ( my $manpage = <> );
# only allow say words and numbers in $manpage
die "Illegal input" unless $manpage =~ m/^\w+$/;
$_ = `man $manpage`;
print m/^DESCRIPTION(.*?)\n\n/ms;
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|