I believe Apache can help you with authentication, it then passes a cookie to the browser and uses that for the remainder of the session. If you want to do this yourself in perl, I would take the same approach. Keep track of this number locally.
Every access updates both the cookie and the local active cookies.
You will also need a cleanup routine that checks for and deletes expired cookies. I'm not a perl programmer myself, but I'm sure this is how my programmers have explained this to me. I hope this helps. I don't see anything in the environment variables. You have to be registered with CLUE to get in.