my $char_for = $codepoint_table{ 'a' }; s{ \x1B ([abcs]) | (.) }{ $1 ? do { $char_for = $codepoint_table{ $1 }; '' } : $char_for->{ $2 } }ge;