Are you doing anything more than inserting a "%" character before every two characters? It certainly appears that way (plus or minus some typing errors, perhaps). Then there is no need for encoding, just simple string manipulation:
my $info_hash = "db8babd3f3662166ee9019e29fd7345af8b2b59a";
$info_hash =~ s/(..)/%$1/g;
This should be recognized just fine by the tracker.
However, if you really want things like %5A to come out as "Z" instead (since they are characters that are safe to use in a URI), then use URI::Escape to do the escaping. It is part of LWP, so is quite common to have installed. First decode the hash from its printable form back into raw bytes and then use URI::Escape to encode those bytes into a URI-safe string.
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);
BTW, if you are computing the info_hash of a bittorrent file, you have the option of getting the result in an printable hex-encoded form "db8b.." or raw bytes "\0xdb\0x8b..." (when you compute the SHA1 hash). You might as well choose to get it in the raw form if you pass it directly to
uri_escape.