1
2
3
4
my $str = "Red and Blue";
my $sbs = "red/green";
my $rex = qr/$sbs/si;
$str =~ s/$rex/g;
1 2 3 4 5
my $str = "Red and Blue"; my $sbs = "red/green"; my ($search, $replace) = split(/\//, $sbs); $str =~ s/$search/$replace/si; print "$str\n";
1 2 3 4 5 6 7 8 9 10 11 12 13
my %replacer = ( foo => "Shrek", bar => "Fiona", ); my $regex = join '|', keys %replacer; $regex = qr{($regex)}; my $text = 'foo runs for bar.'; $text =~ s/$regex/$replacer{$1}/ig; print $text, "\n";