use String::ShellQuote qw( shell_quote ); my $cmd = shell_quote("perl", "-i", "-0777wpe", 'print STDOUT s/foo/bar/g', 'foo_test'); my $num_subs = `$cmd`; die("Can't execute child: $!\n" if $? == -1' die("Child killed by signal ".( $? & 0x7F )."\n") if $? & 0x7F; die("Child exited with error ".( $? >> 8 )."\n") if $? >> 8;