#!/usr/bin/env perl use strict; use warnings; my $search = 'C:\Dir1\Dir2\Dir3'; my $replace = ''; my $var = 'C:\Dir1\Dir2\Dir3\KeepMe'; $var =~ s/\Q$search/$replace/; print "\$var[$var]\n"; #### ken@titan ~/tmp $ perl -v This is perl 5, version 36, subversion 0 (v5.36.0) built for cygwin-thread-multi ... ken@titan ~/tmp $ ./pm_11152209_re_backslashes.pl $var[\KeepMe] #### C:\cygwin64\home\ken\tmp>perl -v This is perl 5, version 26, subversion 3 (v5.26.3) built for MSWin32-x64-multi-thread ... C:\cygwin64\home\ken\tmp>perl pm_11152209_re_backslashes.pl $var[\KeepMe]