It should be possible using
IPC::Open2.
Expect and
IPC::Run also can help. For example, this is a "backticks on steroids" sub from one of my projects:
use IPC::Open2 'open2';
sub backtick {
my ($in, @cmd) = @_;
# $in is a string to pass to STDIN,
# @cmd is a command to run
my $pid = open2(my $stdout, my $stdin, @cmd);
# first we write to stdin
print {$stdin} $in if defined $in; close $stdin;
# then we read the response
my $out = do { local $/; <$stdout> };
# then we wait for the program to die
waitpid $pid, 0;
# beware of deadlocks!
die "$cmd[0] returned $? / error $!\n" if $?;
return $out;
}
You'll need to be careful not to end up in situations where both your script and the script you are controlling via STDIN wait for input from each other. Buffering can also be a problem. More information:
Bidirectional Communication with Another Process.