#!/usr/bin/env perl -l
use strict;
use warnings;
my %lookup = ('500' => '000', '0 988' => '000', '0 1210' => '1000');
my $re = '(' . join('|' => keys %lookup) . ')';
my $string = 'www "999" xxx "0 1210" yyy "500" zzz "0 988"';
print $string;
$string =~ s/$re/$lookup{$1}/g;
print $string;
Output:
www "999" xxx "0 1210" yyy "500" zzz "0 988"
www "999" xxx "1000" yyy "000" zzz "000"
Depending on the context of the strings to be replaced, the pattern may need to be a lot more complex than that shown.
For instance, given '500 988', do you want to replace 500' and ignore ' 988' or ignore '50' and replace '0 988'.
Reading the documentation I linked to will help you understand these issues and how to deal with them.
And, of course, assuming '0 988' is a string to be replaced is just a guess on my part (as I alluded to in the opening paragraph).
|