Leser: 25
$string='abcdefgh%$abc%ijkl';
$abc="XYZ";
$string='abcdefghXYZijkl';
$string =~ s/%\$abc%/$abc/;
1 2 3 4 5 6 7
my %replace = ( abc => 1, def => 2, ... ); my $re = join '|', keys %replace; $string =~ s/%\$($re)%/$replace{ $1 }/g;
1 2 3 4
$abc = 999; $string = 'abcdefgh%$abc%ijkl'; $string =~ s/\%\$([A-Za-z][A-Za-z0-9_]*)\%/${$1}/e; print $string;
Guest Ban-JokeBei der Variante mit dem Hash kann man aber use strict; verwenden??