in reply to out of memory
in thread errors revisited

For one thing, you can cut out a number of arrays by combining what you're doing. From a quick glance, you don't seem to be using @xfilenames (and the like) except as a temporary data structure. Instead, do something like:
my @filenames; my @titles; my @headings; my @stuff; foreach (@pages) { chomp; if (/^\*{4}filename.ext\*{4}/) { s/^\*{4}filename.ext\*{4}//; push @filenames, $_; } elsif (m/^\*{4}title\*{4}/) { s/^\*{4}title\*{4}//; push @titles, $_; } elsif (m/^\*{4}heading\*{4}/) { s/^\*{4}heading\*{4}//; push @headings, $_; } else { s/\*{4}stuff\*{4}(.*?)\*{4}endstuff\*{4}/sg; push @xstuff, $_; } }
You now have 4 less lists, thus cutting your memory usage for data structures almost in half.

Note - don't declare all your variables up-front. That's a very C-like thing to do. Declare them when you need them, as you need them. Declaring a list or hash takes up considerable memory, as Perl will pre-declare like 50 (or so) elements that just sit there.

------
/me wants to be the brightest bulb in the chandelier!

Vote paco for President!