in reply to Substitution with multiple options for capture and replace.

I saw that you could do this with a hash array but was looking for just a regex solution if possible.

The left side is the regex, the right side is perl variable interpolation, and if you use the /e flag, its perl code. so

$_ = "123"; s/(.)/ my $r = " LEFT "; if($1 eq '1'){ $r = " one " } $r /eg; print "$_\n"; __END__ one LEFT LEFT
More in perlretut, perlre

Replies are listed 'Best First'.
Re^2: Substitution with multiple options for capture and replace.
by elmuel (Initiate) on Nov 10, 2009 at 19:21 UTC
    Thanks, I'll try that out. Does anyone know how to do the second regex question I asked about?