in reply to Need to log in through my script to access password protected files.
This sounds a lot like htaccess's Basic Authentication and, alas, I do not believe you can do what you want.
Take a look at Perl and htaccess