switch vs. given vs. for-when vs. if-elsif-else in Perl
<p>In one of the last scripts I wrote, I needed a behavior similar to a switch statement behavior. A simple search of an equivalent in Perl led me to <code>use Switch</code>. At the beginning, all was fine and working, until everything just crashed with errors that are not very descriptive (it happened on a switch statement that had cases with regex, but strangely it didn't happen on other switch statements that are alike).</p>

<p><b>EDIT:</b> the code that crashed was looking like this one:</p>

<pre><code>switch ($var) {
    case /pattern1/ {...}
    case /pattern2/ {...}
    ...
    else {...}
}
</code></pre>

<p>That led me to abandon the use of <code>Switch.pm</code> and search for an alternative.</p>

<p>I found <code>given</code> and <code>for-when</code> and of course there's always the straightforward and somewhat naive <code>if-elsif-else</code>.</p>

<ol>
<li>Why is <code>Switch.pm</code> so unstable?</li>
<li>It seems <code>given</code> and <code>for-when</code> have a similar structure, but I guess there's a difference (because both exist). What is it?</li>
<li>Is <code>if-elsif-else</code> significantly slower than the other options?</li>
</ol>