Typically, the way to do this is to write a Windows Hook DLL. There are a number of sites that will give you help with this using C or VB. Unfortunately the key appears to be the ability to create a DLL to house your hook code which I don't think you can do with perl (I am glad to receive coments if this is not the case).
This link should give you some Ideas.
inman