Why do you need to use script
at all? Is the shell script interactive? Does it need a valid TTY? If it is a non-interactive batch job that doesn't need a valid TTY, then you'd be best off opening it as a pipe and processing the output via a file handle.
For example:
open my $cmd_handle, "-|", $command, @args
or die "Could not run $command @args: $!";
foreach my $line ( <$cmd_handle> )
{
# ... process the command output here ...
}
close $cmd_handle;
This has the advantage that your Perl script will process the command's output as it happens. In case you really do need to defer processing until the end, you could slurp all the output into an array and then process it afterwards:
open my $cmd_handle, "-|", $command, @args
or die "Could not run $command @args: $!";
my @cmd_output = ( <$cmd_handle> );
close $cmd_handle;
foreach my $line ( @cmd_output )
{
# ... process the command output here ...
}
Either ought to be better than running the command via script
if it meets those restrictions I gave above: non-interactive, and does not need a valid TTY. Most batch scripts meet those restrictions.