#!/usr/local/bin/perl $CookieValue = 'テスト'; print "元の文字列:$CookieValue\n"; $CookieValue =~ s/([^\w\=\& ])/'%' . unpack("H2", $1)/eg; $CookieValue =~ tr/ /+/; print "エンコードした文字列:$CookieValue\n"; $rCookieValue = $CookieValue; $rCookieValue =~ s/\+/ /g; $rCookieValue =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("C",hex($1))/eg; print "デコードした文字列:$rCookieValue\n";