sub _quote_envid { local $_ = shift; # RFC 3461: max 100 chars, pass through printable ASCII characters excluding # [ =+], encode others to '+XX' as uc(hex(ord($char))) s{([^\x21-\x7e]|[=+]))}{sprintf "+%02X", ord($1)}ge; # we're usually encoding an email address, so trim long strings from front # to preserve the domain s/^(\+..|.)// while 99 < length; $_; }