in reply to Perl Newbie

Could you try and
1)reduce the code size by eliminating (seemingly) non relevant parts of code (e.g. database handling)
2) re-format the problem statement for clear understanding