#/usr/bin/perl -w use strict; open (TMPOUT,">/tmp/somefile"); my $from; my @recipients; while (<>) { print TMPOUT unless (/^From: /i || /^To: /i); ($from = $_) =~ /Some regex to get from/ if (/^From: /i); } close (TMPOUT); open (PASSWD,"/etc/passwd"); while () { my @fields = split ":" , $_; push @recip , $fields[0] unless (#system account); } system (cat /tmp/somefile|sendmail -bm -f"$from" "@recips"); unlink "/tmp/somefile";