in reply to Problem with regex substitution within windows paths

Your string replacement contains characters that are special to the regex engine. See perlop on \Q resp. quotemeta.

Replies are listed 'Best First'.
Re^2: Problem with regex substitution within windows paths
by halfcountplus (Hermit) on Jul 08, 2011 at 17:42 UTC

    > characters that are special to the regex engine

    Namely, \, the escape character itself. So you need to escape the escape: \\.

Re^2: Problem with regex substitution within windows paths
by jmb (Novice) on Jul 11, 2011 at 12:32 UTC
    Thank you Corion ! The code now works :
    #!/usr/bin/perl -w use strict; use warnings; my $path = join ';', ( 'D:\aa\bb\cc', 'D:\dd\ee\ff', 'D:\gg\hh\ii', ); my $path_component = quotemeta( 'D:\aa\bb\cc;' ); print $path, "\n\n"; $path =~ s/$path_component//i; print $path, "\n\n";
    ... and, more importantly, I've now understood what was going wrong...