This is my code:
$html = 'Is this a question? Maybe.';
$old = 'question?';
$new = 'reply?';
$html =~ s/$old/$new/g;
print $html; exit;
Output is:
Is this a reply?? Maybe.
Desired output:
Is this a reply? Maybe.
What am I doing wrong?
Use quotemeta to escape the ?:
$html = 'Is this a question? Maybe.';
$old = quotemeta 'question?';
$new = 'reply?';
$html =~ s/$old/$new/g;
print $html; exit;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With