open (MAN, "/usr/bin/man ssh |"); while () { s/^\s+//g; push(@ml,$_); } foreach $line (@ml) { $line =~s/\n$//; $line =~s/^\n//; $line =~s/^\s+//; } for ($x=0; $x<=45; $x++) { if ($ml[$x]=~/NAME/) { while($ml[$x] !~/SYNOPSIS/) { $nl .= $ml[$x] } } }