use URI::Escape; my $info_hash = "db8babd3f3662166ee9019e29fd7345af8b2b59a"; $info_hash =~ s/(..)/chr hex $1/ge; # or a suitable call to pack, but I'm lazy right now my $uri_hash = uri_escape($info_hash);