in reply to Allocation of anonymous arrays
No, Perl won’t put two arrays into the same storage just because (at the moment ...) their values are identical. But ... in practice, it sure is easy to come into a situation where you think that it did ... where you think that you’re just changing a value “over here,” and ... (gasp!) ... a value “over there” just changed, too!
What will actually turn out to have happened, in those cases, is that you had a reference to the same list of values in two or more places ... that you thought that you were telling Perl to move (to duplicate) an array or a hash (something that requires to be “referenced” ...). But what Perl was actually doing was creating references. It seemed to work, until you changed what you thought was an independent, isolated value, and saw that the changes had apparently propagated. Easy to do. And the [erroneous ...] explanation, that the optimizer did something wrong, is also an intuitively-appealing assumption.
Perl tries hard to be a “DWIM = Do What I Mean, TMTOWTDI = There’s More Than One Way To Do It™” language, and so its very-flexible syntax is occasionally misleading. If you are used to dealing with strongly-typed and/or compiled languages where there’s really only one way to do it and where any deviations from that will be caught for you at compile time ... Perl isn’t like that. Its design is not like that, which is neither right nor wrong.