#!/bin/sh str="Hello" out=$(perl - $str << 'EOF' $str2 = shift; $str3 = "world"; print "$str2 $str3\n"; EOF ) str3=$(echo $out|cut -d' ' -f2) echo $out echo "In the shell, \$str3 is '$str3'"