use strict; use warnings; my %replacement = ( '?a?' => 'aRep', '?b?' => 'bRep', '?c?' => 'cRep', ); my $regex = join '|', keys %replacement; $regex =~ s/\?/\\\?/g; my $string = '?a? ?b? ?c?'; print "old string: $string\n"; $string =~ s/($regex)/$replacement{$1}/ge; print "new string: $string\n";
In reply to Re: Replace multiple strings in a string
by BillKSmith
in thread Replace multiple strings in a string
by Axlex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |