in reply to capture stdout and stderr from external command

Take a look at IO::CaptureOutput. It will allow you to capture stdout and stderr returned from external commands.