email parsing->mysql:: Can someone explain me this perl script?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I am a perl noob that can learn if you give me a hand.
I currently need a script to read emails using email piping,
extract some information and put it inside a MySQL database.

The reason? Make some statistics of my email server antivirus.

The sample body of my emails is as follows:

-----------------> Source of Sample email source <---------

Subject: Advertencia: Virus detectado en e-mail
Date: Sun, 29 Aug 2004 17:33:08 -0500
Se han encontrado virus en el siguiente e-mail:
IP Address:
MessageID: 1C1YEL-0002Zn-VA
Informe: contains Worm.Mydoom.M
-----------------> Source of Sample email source <---------

For this purpose I got this script (called amavistat), however
I need that someone tells me what modifications should I do to
to make it work in my case, here I am attaching the source of
the script

# Veghead 2001
# Fixed stupid '=' vs 'eq' bug - Veghead 2003-08-14

use DBD::mysql;

$dbh=DBI->connect("DBI:mysql:$dbname:$server",$username,$password) or
                                        die("Can't connect to MySQL");


while(<>) {
    if ($state eq "inheader") {
        if (length($_)<2)
        elsif ($_=~/^Subject: VIRUS FROM <(.*)> \((.*)\)/) {
    } elsif ($state="inbody") {
            if ($viruswarn)

sub do_something {
    foreach $vname ($viruses) {
                print "From: $virusfrom\nTo: $virusto\nVirus: $vname\n\n";
                $sth = $dbh->prepare("insert into $table values

Site Timeline