#!/bin/bash
export IPV6=$1
expanded_ipv6_addr=`perl -e 'require "/usr/bin/ipv6_helper.pm"; $expand_ipv6=expand_ipv6_addr($ENV{IPV6});print $expand_ipv6'`
I don't want to export the $IPV6 variable, so I am looking any other way to do this.
Instead of exporting $1 into an environment variable you could use it again later and escape the perl code.
The following worked for me with a stubbed out version of /usr/bin/ipv6_helper.pm
#!/bin/bash
IPV6=$1
expanded_ipv6_addri=`perl -e "
require \"/usr/bin/ipv6_helper.pm\";
\\$expand_ipv6 = expand_ipv6_addr($IPV6);
print \\$expand_ipv6
"`
./expand 2001:0db8:85a3:0000:0000:8a2e:0370:7334 gives a number of syntax errors because expand_ipv6_addr(2001:0db8:85a3:0000:0000:8a2e:0370:7334) is not valid Perl code../expand '".malicious()."'. Generating code is an awful idea. Instead, you should use a parameter, the environment (which the OP forbade for unknown reasons), STDIN, etc.
expand_ipv6_addrthat expands addresses given as command line arguments?perlvia its environment?