while($inp =~ /<%=(.*?)%>/s) { print "Dollar 1 before eval = $1\n"; $inp =~ s/<%=(.*?)%>/eval $1/es; print"INP after substitution = $inp\n"; } # only the concerned part of code with this extraction is written here