$text2 = 'foo|abc-./|foo '; # $text2 =~ s%(foo|\w+)([//.-]+)(.*)%$1 :i: $2 :i: $3%g; # output is: ++foo|abc :i: -./ :i: |foo ++ # captures the hyphen, dot and slash in $2 with ONLY the fwd_slash escaped # and capturs "|foo " in $3 # $text2 =~ s%([\w|]+)([.-]+)(.*)%__$1_:_$2_:_$3__ : second variation%g; # output is: ++__foo|abc_:_-._:_/|foo __ : second variation++ # hyphen, dot still captured in $2 with no escaping at all inside the class $text2 =~ s%([\w|]+)([.-]+/)(.*)%$1:$2:$3 : third variation%g; # output is: ++foo|abc:-./:|foo : third variation++ # Moved the fw_slash (unescaped, using % as delimiters) into the second capture # expression... and fw_slash turns up correctly in $2 print "\t++$text2++\n";