in reply to Collecting the output of command prompt

You should look up `` backticks (it's in perlop under Quotes) or piped opens.

If your other programs require something more sophisticated look into Expect.pm

This is also a FAQ 'perldoc -q command output'

grep
grep> cd pub grep> more beer