use strict; my ( $dfrom, $dsubj ); my $from = shift; while ( defined( $_ = ) ) { if ( substr($_,0,5) eq 'From:' ) { chomp($dfrom = substr($_,6);) last; } } if ( $dfrom && $from ne $dfrom ) { seek(STDIN,0,0); ... save copy and log ... } seek(STDIN,0,0); ... Clamav call by stream ... if ( ... virus found ... ) { ... warn mail ... exit; } seek(STDIN,0,0); open(AS, "| ... anti spam binary") or die " ... error string "; syswrite(AS, $buf) while ( read(STDIN, $buf, 32768) ); close(AS); }