请高手指教啊,ruby -> prel

请高手指教啊,ruby -> prel

def unescape(string)
  string.gsub(/((?%|\\x)[0-9a-fA-F]{2})+)/n) do
    s = $1.gsub!(/(%|\\x)/, '')
    [s].pack('H*')
  end
end

这段用perl怎么写啊?
请高手赐教啊。
$str =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
$str =~ s/\\x([0-9A-Fa-f]{2})/chr(hex($1))/eg


$str =~ s/(\\x|%)([0-9a-fA-F]{2})/chr(hex($2))/ge;