use v5.36; my %named_char= ( a => "\a", b => "\b", t => "\t", n => "\n", v => chr(11), f => "\f" ); my $line= ; if ($line =~ / ^"( # starts with doublequote (?> # no backtracking [^"\\]+ # allow any character other than \\ or " | \\[^xuU0-7] # escaped character other than \x \u \U \0-7 | \\[0-7]+ # octal escape | \\x[0-9a-fA-F]{1,2} # hex escape | \\u[0-9a-fA-F]{1,4} # unicode escape | \\U[0-9a-fA-F]{1,8} # )* # repeat as needed )" # stop at next doublequote /x) { my $literal= $1; my $op; $literal =~ s/\\( [^xuU0-7] (?{ $op=sub{ $named_char{$1} || $1 } }) | [0-7]+ (?{ $op=sub{ chr oct $1 } }) | x[0-9a-fA-F]{1,2} (?{ $op=sub{ chr hex substr $1,1 } }) | u[0-9a-fA-F]{1,4} (?{ $op=sub{ chr hex substr $1,1 } }) | U[0-9a-fA-F]{1,8} (?{ $op=sub{ chr hex substr $1,1 } }) ) / &$op /xge; use DDP; p($literal); }