in reply to Perl and Shell (text conversion)

without trying it out, this looks plain wrong

 $result = '';

because it breaks your evaled string delimiter

perl -e ' ...

maybe try

  $result = q();

instead.

q/STRING/ is an alternative syntax for '' , see perlop#Quote-and-Quote-like-Operators for details

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

update

PS: please note that bash has here-docs too, maybe a more flexible way to safely integrate literal Perl code.