use Unicode::String qw/utf8/; my $name = "трудная строка"; my $u=utf8($name); # ready; use it at your will: my $s = $u->hex; $s=~s/U\+00(\w\w)/my($r,$p)=((pack 'H*',$1),$&);if($r=~m(^[\w ]$)){$r}else{$p}/eg;