title: How to substitute and replace on expression using hash with multi-character variables?
body: <p>My current script will take an expression, ex:</p>
  
  <pre><code>my $expression = '( a || b || c || ab || ca)';
  </code></pre>
  
  <p>and go through each boolean combination of inputs using sub/replace, like so:</p>
  
  <pre><code>my $keys = join '|', keys %stimhash;
  $expression =~ s/($keys)\b/$stimhash{$1}/g;
  </code></pre>
  
  <p>In the above example, assuming:</p>
  
  <pre><code>a =&gt; 0, b =&gt; 1, c =&gt; 0
  </code></pre>
  
  <p>The expression should become:</p>
  
  <pre><code>( 0 || 1 || 0 || ab || ca )
  </code></pre>
  
  <p>This works great.</p>
  
  <p>However, I would like to allow the variables (also in <code>%stimhash</code>) to contain a tag, <code>*.</code></p>
  
  <pre><code>my $expression = '( a* || b* || c* || ca || ab )';
  </code></pre>
  
  <p>Also, printing the keys of the stimhash returns:</p>
  
  <pre><code>a*|b*|c*
  </code></pre>
  
  <p>It is not properly substituting/replacing with the extra special character, <code>*.</code>
  It gives this warning:</p>
  
  <pre><code>Use of uninitialized value within `%stimhash` in substitution iterator
  </code></pre>
  
  <p>I tried using <code>quotemeta()</code> but did not have good results so far.
  It will drop the values. An example after the substitution looks like:</p>
  
  <pre><code>( * || * || * || ca || ab )
  </code></pre>
  
  <p>instead of:</p>
  
  <pre><code>( 0 || 1 || 0 || ca || ab )
  </code></pre>
  
  <p>As you can see the <code>/b</code> is used to prevent partial substitutions. Sorting the keys by length does not solve the problem because some variables are not being replaced (<code>ca</code> and <code>ab</code> in above example).</p>