In perl, you can pass a string to a command's stdin.
use IPC::Cmd qw{run_forked};
my $applescript = q{display alert "Hello, world!"}
my $results = run_forked( 'osascript', {child_stdin => $applescript} );