Sendmail / Aliases

I'm trying to make a script that will automatically read incoming mail, parse the recipient, then send a file off to the recipient.
(Name of file =
$mailDir = "/var/spool/mail/"
$user = print `cat <STDIN> | grep To: | cut -b5-`;
print `elm -s Awaiting Mail $user < /tmp/alert";

And the entry in the aliases file goes:
test: "| /home/mail/"
is that correct aswell?

a standard way to filter incoming mail is to configure procmail. It's easy & really usefull. and with procmail you can handle the problem you face perfectly than a perl script.

for more info man procmail & man procmailex