You got your single and double quotes backwards.
Looks like you need to say:
$aword = 'foo'; # use single quotes instead of double $containmentvar = "$aword"; # use double quotes instead of single
Variables between double quotes will be interpolated to their values, but between single quotes they will be taken literally.

Hope this helps,
Jeff

UPDATE:
Hmm, when I first read your post, I thought you were wanting symbolic references - I have to agree with tilly on this one, and do read ar0n's link that he provided, but here you go anyways:

$aword = 'foo'; $containmentvar = 'aword'; # no dollar sign here $$containmentvar = 'bar'; # foo or bar? print "$aword\n";
Remember, you can't use strict with this code, that should be reason enough to find another solution, but if you aren't coding heart monitoring devices you should be ok.

Now that I have handed a loaded gun to somebody, I am going to find a lawyer.


In reply to (jeffa) Re: substitution of variable within a variable by jeffa
in thread substitution of variable within a variable by TecoDaN

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.