This question really deserves some research
on your part... and in the Perl world that basically means CPAN
Let's face it: you are not
the first person on the planet to have needed a good way to "solve the validation and/or authentication problem" in an application. Others have solved the problem in hundreds of ways before you, and they've put a boatload of well-tested solutions into CPAN.
Don't reinvent... anything. Ever.
Dictum Ne Agas: Do Not Do A Thing Already Done.
Instead of banging your head against this trivial problem "yet again," search for an existing module that you can install and use
Your time is much better-spent on the concerns that make your application unique,
not the routine concerns that are identical for every application in the universe.
And mind you, I do not mean this as a "slam."
It is hard
to train yourself to think this way, and you very-easily forget. Me, too. Mea culpa.
Just last week I was sorta-showin'-off a little-clever-thing I'd sorta-come-up with ... and he casually mentioned a CPAN module that I coulda-sorta-just USED and he gave me this good-natured slight-smile and ...
... well, it kinda-sorta keeps ya in your place
until you can sneak out by the water cooler and say "Doh!!!"