in reply to attempting to achieve something

Not much of a communicator are we?

use strict; use warnings; use feature 'say'; sub mixedregex { my $foo = shift; say length $foo; $foo =~ s{\0([0-7]{3})}{chr oct $1}eg; say length $foo; return $foo; } say mixedregex("bar"."\0"."123"); __END__
$ perl 11142131.pl 7 4 barS

Hope this helps!


The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: attempting to achieve something (escaping rules)
by LanX (Saint) on Mar 16, 2022 at 15:06 UTC
    > "bar"."\0"."123"

    when using doublequotes or interpolated regexes one needs to escape a leading backslash, hence "\\0"

    your code is not replacing the string '\0' but the chr(0)

    DB<13> x "\0" 0 "\c@" DB<14> x chr(0) 0 "\c@" DB<15> x '\0' # with singlequotes escaping is only needed for \ and +' 0 '\\0' DB<16> p '\0' eq '\\0' 1

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery