in reply to cookie problem

elsif(my $cookie) {
That should probably be:
elsif($cookie) {

or just:

else {