s/(.)/ord($1)>127 or ord($1)<=32 ? sprintf("%%%02x",ord($1)) : $1/se; #### for my $ofs (0..length($str)-1) { my $c=substr($str,$ofs,1); substr($str,$ofs,1)=sprintf("%%%02x",ord($c)) if ord($c)>127 or ord($c)<=32; }