use Encode; # ... # assuming the source string is in $_: s/%([0-9A-F]{2})/chr(hex($1))/egi; # convert "%HH" to binary bytes $_ = decode( 'utf8', $_ ); # flag the string as utf8 data