Besides the cost of holding everything at once in memory,
your code incurs
the cost of unedeed strings copy. There is no such things as "copy on write strings" where the strings value
would be shared until modified. BTW, It is not clear that the
overhead of implementing "copy on write strings" in Perl will be less than the ones imposed by the undeeded allocation and copy of strings.
-- stefp