Search and replace a particular string having special characters in a file using Perl : Search and replace a particular string in a file using Perl.
I have a .txt file. where i need to search and replace a string.
i code i have is working fine for string not having special characters.but for the string containing special characters like (?,=,:: ) is not working with this code. Can anyone please urgently help??
Thanks in advance.

a.txt file content:
------------------
<tbody>
							<tr><td> App URL </td><td> <xmp class="no-margin" style="white-space:pre-wrap">https://example.com/abc/f?p=CDE:HOME/</xmp> </td></tr><tr><td> App control </td><td> <xmp class="no-margin" style="white-space:pre-wrap">SSO</xmp> </td></tr><tr><td> App Owner </td><td> <xmp class="no-margin" style="white-space:pre-wrap">CCS</xmp> </td></tr>
							</tbody>

-----------------------------
Need to replace in a.txt file:
<xmp class="no-margin" style="white-space:pre-wrap">https://example.com/abc/f?p=CDE:HOME/</xmp>
----------------------------
Replacement String:

<a href="https://example.com/abc/f?p=CDE:HOME/" target="_blank">https://example.com/abc/f?p=CDE:HOME/</a>
---------------------------

#!/usr/bin/perl

use strict;
use warnings;

$^I = '.bak'; # create a backup copy 

my $string2 = '<xmp class="no-margin" style="white-space:pre-wrap">https://example.com/abc/f?p=CDE:HOME/</xmp>' ; #old string
my $string3 = '<a href="https://example.com/abc/f?p=CDE:HOME/" target="_blank">https://example.com/abc/f?p=CDE:HOME/</a>'; #new string

while (<>) {
   s/$string2/$string3/g;
  
   print; # print to the modified file

expected result in a.txt file after replacement:
----------------------------------------------
<tbody>
							<tr><td> App URL </td><td> <a href="https://example.com/abc/f?p=CDE:HOME/" target="_blank">https://example.com/abc/f?p=CDE:HOME/</a> </td></tr><tr><td> App control </td><td> <xmp class="no-margin" style="white-space:pre-wrap">SSO</xmp> </td></tr><tr><td> App Owner </td><td> <xmp class="no-margin" style="white-space:pre-wrap">CCS</xmp> </td></tr>
							</tbody>