$data =~ s{ ([^\w\s\xA0~!@#$%^&*\-_=+()[\]{}|;:'`",<.>/?\xA9\xA7]) }{ sprintf "{U+%04X}", ord($1) }xeg; #### use charnames qw( :full ); $data =~ s{ ([^\w\s\xA0~!@#$%^&*\-_=+()[\]{}|;:'`",<.>/?\N{COPYRIGHT SIGN}\N{SECTION SIGN}]) }{ sprintf "{U+%04X}", ord($1) }xeg;