A fairly different approach would be to use a web framework. I've looked at Catalyst, and it appears to have a whole lot of modules and plugins which automate the approaches other people have discussed.
If developing, you'll want both 'Task::Catalyst' and 'Catalyst::Devel' from CPAN.
Working within the framework is a little different to writing your own code and certainly to start with feels odd. But if you invest the time to learn how not to fight it, you'll get the benefit of pre-written (and debugged!) authentication modules etc.