in reply to Dealing with uninitialized values

How are you running it? If you run it the first time, of course there will be nothing in the username parameter, and you'll get errors.

By the way:

my $query = new CGI->new();

... you can safely drop the first new there.