This is only a Perl problem once you know how to "hook in" to your eMail software. If you're using sendmail, qmail, procmail, or postfix, there are different mechanisms for doing this. Something like a .forward (or .qmail, or .vacation) file might be what you are looking for.
Check the appropriate manual pages for your OS and/or eMail delivery agent. (Note that the program which delivers eMail, the MDA - e.g. "procmail" - may not be the program which receives eMail from the network, the MTA - e.g. "sendmail")
The next question would be, what do you want to do? Simply replying with a text message can be done by any of the above MDA's. If you want to do something more complex, we'll need to know more about your OS and MDA set-up.