You're almost there.
When you're using a regular expression, the regexp itself can't be a variable (the contents between the / delimiters can). So, for the above:
my $STR = "AAXXXAA";
$STR =~ s/AA/BB/g;
Rather than assigning to the regular expression to a variable, then using the =~ operator on it, you need to apply the regular expression directly.
If the contents of the regexp are going to change at runtime, you can place these into variables:
my $sub_str = "AA";
my $sub_val = "BB";
my $str = "AAXXXAA";
$str =~ s/$sub_str/$sub_val/g;
Hope this helps .. --Foxcub |