Suppose the variable $var has the value abc123abc . What is the value of $var after the following substitution? $var=~ s/(\d+)/ $1*2 /e ;
-
“abc”
-
It will produce error
-
“ABC123ABC”
-
”abc246abc”
The regex /e modifier evaluates the replacement as Perl code. It matches 123, captures it in \$1, then evaluates 123*2=246. The substitution replaces 123 with 246, resulting in abc246abc. Option D is correct. Without /e, it would treat \$1*2 as literal text. The /e modifier enables dynamic computation in regex replacements.
"abc246abc" is correct. The /e modifier on a Perl substitution tells Perl to evaluate the replacement text as executable Perl code rather than treating it as a literal string. Here the pattern (\d+) captures "123" from "abc123abc" into \$1; the replacement code " \$1*2 " — surrounding whitespace is insignificant in Perl code — evaluates the expression \$1*2, i.e. 123*2 = 246, and that numeric result (246) is what gets substituted in place of the matched "123", yielding "abc246abc". Without /e, the literal string " \$1*2 " (with $1 interpolated but *2 left as text) would have been inserted verbatim, which is what makes this a genuine /e-modifier test rather than a plain substitution.