Couple of things:
#! /usr/bin/perl -wT
use strict;
is your friend. - You're using global variables $rname etc when you should probably be using local variables. That's just good coding technique.
- You probably should be implementing cookies using CGI instead of hand rolling it, at least initially. (As an exercise is cool of course...)
Now, I'm not entirely sure exactly how
$ENV->{'HTTP_COOKIE'} gets set, but I would imagine it wont be set until your cgi is called the second time around. (Someone correct me if I'm wrong.) In the meantime, why don't you try printing the contents of
$ENV->{'HTTP_COOKIE'} to stderr to see if it's actually set?