Interpreting & modifying Perl one-liner?
<p>I have the following Perl 'one-liner' script (found it online, so not mine):</p>

<pre><code>perl -lsne '
    /$today.* \[([0-9.]+)\]:.+dovecot_(?:login|plain):([^\s]+).* for (.*)/
    and $sender{$2}{r}+=scalar (split / /,$3)
    and $sender{$2}{i}{$1}=1;

    END {
        foreach $sender(keys %sender){
            printf"Recip=%05d Hosts=%03d Auth=%s\n",
                $sender{$sender}{r},
                scalar (keys %{$sender{$sender}{i}}),
                $sender;
        }
    }
' -- -today=$(date +%F) /var/log/exim_mainlog | sort
</code></pre>

<p>I've been trying to understand its innards, because I would like to modify it to re-use its functionality.</p>

<p>Some questions I got:</p>

<ul>
<li>What does the flag <em>-lsne</em> does? (From what I know, it's got to be, at least, 3 different flags in one)</li>
<li>Where does <em>$sender</em> gets its value from?</li>
<li>What about that <em>(?:login|plain)</em> segment, are they 'variables'? (I get that's ReGex, I'm just not familiarized with it)</li>
</ul>

<p>What I'm trying to achieve:</p>

<ul>
<li><p>Get the number of emails sent by each user in a SMTP relay <em>periodically</em> (cron job)</p></li>
<li><p>If there's an irregular number of emails (say, 500 in a 1-hour timespan), <em>do something</em> (like shutting of the service, or send a notification)</p></li>
</ul>

<p><strong>Why</strong> I'm trying to achieve this:
Lately, someone has been using my SMTP server to send spam, so I would like to monitor email activity so they stop abusing the SMTP relay resources. <em>(Security-related suggestions are always welcomed, but out of topic for this question. Trying to focus on the script for now)</em></p>

<p>What I'm <strong>NOT</strong> trying to achieve:</p>

<ul>
<li>To get the script done by third-parties. (Just try and point me in the right direction, maybe an example)</li>
</ul>

<p>So, any suggestions, guidance,and friendly comments are welcomed. I understand this may be an <em>out-of-topic</em> question, yet I've been struggling with this for almost a week and my background with Perl is null.</p>

<p>Thanks in advance.</p>