use IPC::System::Simple qw( capturex ); # Core module my @cmd = ( 'perl', '-i', '-0777wpe', 'print STDOUT s/foo/bar/g', 'foo_test' ); my $num_subs = capturex(@cmd); die("Child exited with error ".( $? >> 8 )."\n") if $? >> 8;