also look into using sockmark so you don't have to set global vars.
as well if you are going to use $regex why not use $regml as well?
also the script is a bit floody maybe make it notice instead of msg or have it list a number of results like maybe 3
cuz !def cat gave back 10 lines thats more then enough to get you banned from some channels.