Substitution and interpolation with variables

Question

my @rules = (
    ['^HELLO (.*)$', 'BONJOUR $1'],
    # ... lots of other rules
);

foreach my $rule (@rules) {
    if ($string =~ s/$rule->[0]/$rule->[1]/e) {
       last;
    }
}

With this code, 'HELLO WINSTON' becomes 'BONJOUR $1' and not 'BONJOUR WINSTON' as I'd like.

Winston Smith's original post Next

Next