in reply to maximum length of scalar in theory

System limits:

32-bit x86 OS typically provide a flat 32-bit address space, putting an upper bound of 2^32 bytes.

64-bit x86 OS typically provide a flat 64-bit address space, putting an upper bound of 2^64 bytes.

Some of the memory space is reserved by the OS, either to communicate with it, or to protect from common error (such as dereferencing a NULL or low-value pointer). Some of the memory is used by the program. These will lower the maximum size you can allocate.

Perl limits:

The size of a string must fit in a STRLEN. This is a define to size_t. So this really isn't a limit at all.