in reply to Help with Regexp substitution using variables

The following works, but you risk injecting commands into your script. To do it properly, you'd have to do the variable interpolation yourself.

my ($reg, $reg2) = @ARGV; my $string = "how1=on&how2=on"; $string =~ s/$reg/ eval "\"$reg2\"" /eg; print $string;

Replies are listed 'Best First'.
Re^2: Help with Regexp substitution using variables
by Roy Johnson (Monsignor) on Jan 20, 2005 at 17:41 UTC
    Or
    $string =~ s/$reg/qq{qq{$reg2}}/eeg;

    Caution: Contents may have been coded under pressure.
      I like making the eval EXPR evident over adding a second /e, because of the inheritant risks to using them.