The first technique builds the final string by concatenating smaller strings, avoiding interpolation but achieving the same end. Because
print
effectively concatenates its entire argument list, if we were going to
print
$phrase
, we could have just said:

print "I have ", $n + 1, " guanacos.\n";

When you absolutely must have interpolation, you need the punctuation-riddled interpolation from the Solution. Only
@
,
$
, and
\
are special within double quotes and most backquotes. (As with
m//
and
s///
, the
qx()
synonym is not subject to double-quote expansion if its delimiter is single quotes!
$home
=
qx'echo
home
is
$HOME';
would get the shell
$HOME
variable, not one in Perl.) So, the only way to force arbitrary expressions to expand is by expanding a
${}
or
@{}
whose block contains a reference.

You can do more than simply assign to a variable after interpolation. It's a general mechanism that can be used in any double-quoted string. For instance, this example will build a string with an interpolated expression and pass the result to a function:

Expanding
backquotes (
``
) is particularly challenging because you would normally end up with spurious newlines. By creating a braced block following the
@
within the
@{[]}
anonymous array dereference, as we did in the last example, you can create private variables.

Although these techniques work, simply breaking your work up into several steps or storing everything in temporary variables is almost always clearer to the reader.

In version 5.004 of Perl,
${\
EXPR
}
wrongly evaluates
EXPR
in list instead of scalar context. This bug is fixed in version 5.005.