open(my $shell, "|-", "sudo perl") or die "Can't pipe to bash: $!"; print $shell "$password\n"; sleep(1); # Make sure that Perl has started. This is likely unneeded. print $shell $some_perl_script; close($shell) or die $! ? "Error closing pipe: $!" : "Exit status $? from perl child";