perl -00 -ne 'print if /--Begin--/ && /--End--/' file.txt #### Hello World --Begin-- Cat and Dog --End-- other stuff This is a test Good Bye #### --Begin-- Cat and Dog --End-- #### export REX="/--Begin--/ && /--End--/" echo $REX /--Begin--/ && /--End--/ #### perl -00 -ne 'BEGIN {$rex = $ENV{REX}} print if qr($rex)' file.txt #### perl -00 -ne 'BEGIN {$rex = qr($ENV{REX})} print if $rex' file.txt