$dir1="D:\\Windows\\programs1";
$dir2="D:\\Windows\\programs2";
$file1 = ="D:\\Windows\\programs1\\a.txt";
($file2 = $file1) =~ s/$dir1/$dir2/esg;
print "file1 -> $file1\n";
print "file2 -> $file2\n";
####
file1 -> D:\Windows\programs1\a.txt
file2 -> D:\Windows\programs2\a.txt
####
file1 -> D:\Windows\programs1\a.txt
file2 -> D:\Windows\programs1\a.txt