in reply to CGI Script sub

Try putting

use CGI::Carp qw/ fatalsToBrowser /;
at the top of your script. This will make the cause of the error appear in the browser. Right now it is in the web server error log.

See CGI::Carp

P.S. Also see Regexp::Common ... some of what you are doing has been done before ;-)

The way forward always starts with a minimal test.