This thread has turned into the "Perl Quiz of the Week" #1! ;-)
Write a subroutine, 'subst', which gets a string
argument, $s. It should search $s and replace any
occurrences of "$1" with the current value of $1, any
occurrences of "$2" with the current value of $2, and
so on.
For example, if $1, $2, and $3 happen to be "dogs",
"fish" and "carrots", then
subst('$2, $1 and $3')
should return
"fish, dogs, and carrots"
dominus' post-mordem analysis of this problem can be found
here. He offers several solutions and some discussion of why (and why not) to use them.