sub my_sys { my $out = pop; my $pid = fork(); die "couldn't fork" unless defined $pid; if ($pid) { wait; } else { close STDOUT; open STDOUT, ">", $out or die "open '$out' failed: $!"; exec @_; die "exec failed: $!"; } } my_sys("/bin/echo", "foo", "bar", "std.out"); #### $ ./935901.pl $ cat std.out foo bar