Check your webserver logs, or if you can't access them put use CGI::Carp 'fatalsToBrowser'; at the top of your script. (Remember to remove the fatalsToBrowser bit when the script is on the live server!) For me, when I test run this code, I get your die's message that the directory could not be opened. Be aware that when called from the webserver, the current working directory of the script is not necessarily the directory the script resides in.