in reply to Using a regex saved in an environment variable

Now I want to do the same thing except put the regular expression in an environment variable:

export REX="/--Begin--/ && /--End--/" echo $REX /--Begin--/ && /--End--/
But that's not a regexp; that's an expression.

You can do the interpolation in the shell, so that Perl sees what you intent it to see:

perl -00 -ne 'print if '$REX file.txt
Here, $REX is exposed to the shell, which sees the above as:
perl -00 -ne 'print if /--Begin--/ && /--End--/' file.txt