Да, задачка не простая. Ну вот попробуй, что получилось :
Код:
$input = "VaSiA%C2%C0%D1%DF"; # VaSiAВАСЯ
$s = $input;
$s =~ s/%([0-9a-fA-F]{2})/chr hex($1)/ge; # convert to char
$hex = lc $s; # low case ascii chars
$hex =~ tr#\xC0-\xDF#\xE0-\xFF#; # low case non-ascii chars
$out = $hex;
$out =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg; # URL-encode data
print "input=$input\nhex=$hex\nout=$out\n";
# My output in UNIX :
# input=VaSiA%C2%C0%D1%DF
# hex=vasiaâàñÿ
# out=vasia%E2%E0%F1%FF