$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; #### s/ % ## find (and discard) the % char ( ## capture [a-fA-F0-9][a-fA-F0-9] ## two hex charcters to $1 ) / pack("C", hex($1)) ## convert hexcharacters to a number, ## then pack to a character /eg; ## replace all in the target string