title: perl matching optional regex
body: <p>I'm struggling to come up w/ a regex in Perl to match a string with optional prefixes and suffixes.</p>
  
  <p>Here is my expression so far:</p>
  
  <pre><code>my $string = "prefix1_foo_suffix2";
  if ($string =~ m/^(prefix1_|prefix2_)?(prefix3_|prefix4_)?foo|bar(_suffix1|_suffix2)?$/) {
    print "match"
  };
  </code></pre>
  
  <p>So this should match strings like </p>
  
  <pre><code>prefix1_foo_suffix2
  prefix1_prefix4_bar
  bar_suffix2
  </code></pre>
  
  <p>but not </p>
  
  <pre><code>prefix1_baz_suffix2
  bar_suffix42
  </code></pre>
  
  <p>As far as I can tell, though, this is matching any suffix (ie: anything after "foo" or "bar").  Any ideas on what I've done wrong?</p>