There are lots of CPAN modules to make this easier. If it's just a command you're running and you don't need to manage its STDIN, I'd use IO::CaptureOutput, which is my favorite swiss-army tool for capturing output either from Perl or from an external command. (So much my favorite that I took over maintainership when I needed bugs fixed and the author was non-responsive.)
use IO::CaptureOutput qw( qxx );
my ($stdout, $stderr) = qxx( $somecommand, @args, $filename );
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.