my $output; { my @command = "sudo", "/usr/bin/python", "/home/processLog.py", $name, $age, $text, $id; open my $P, "-|", @command or die "error pipe opening program"; local $/; $output = <$P>; close $P or die "error: spawned program exited with failure or cannot read pipe"; # note: you may want to accept an exit failure with some programs. if you do, check eof($P) instead to catch a read error. } print $output;