use IPC::Open3 qw( open3 ); sub launch_in_background { my ($prog, @args) = @_; open(local *CHILD_STDIN, '<', '/dev/null') or die $!; if (!@args) { # Make sure $prog isn't interpreted as a shell command. @args = ('-c', 'exec "$1"', 'dummy', $prog); $prog = '/bin/sh'; } return open3('<&CHILD_STDIN', '>&STDOUT', '>&STDERR', $prog,@args); } my $pid1 = launch_in_background('prog', 'file1'); my $pid2 = launch_in_background('prog', 'file2');