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