Apache automatically puts the logged-in username in the REMOTE_USER enviromnent variable, which can be accessed by any CGI program. In Perl, it's $ENV{'REMOTE_USER'}.