Too many things were wrong with that script. One, you had too many unmatched brackets, the $text variable was being used in the wrong spot (sub EVENT_ITEM does not export $text to the script), you had non-matching elsifs (each elsif requires a matching if)... I suggest you go here and read up on perl and not throwing things together and hoping they work, this site really helped me:
http://www.tizag.com/perlT/