This will make a copy of the array and give a reference to that, right? Is there a way to get a reference directly to the array passed back by sub1 with some assurance the copy won't happen? Or is this the sort of optimization that is up to the compiler (and may or may not happen?)?
This example makes me think of rvalue references and move semantics in the new C++, where you can now return a std::vector, say, and be assured that the copy will really only grab the innards of the temporary returned rather than allocate anything new and copy things over. I wonder if there's something roughly equivalent in Perl (5 or 6).