Thanks for taking the time to reply to my posts.
The strings are being used to parse a netlist, modify the parse tree, and rewrite the netlist with the alterations. Netlists can be very large. The alterations can be small and inserted into the original string at anchors calculated using pos during the parse.
As I alluded in my original post, one of my concerns is memory usage. It would be nice to be able to handle Files as if they were not streams, but I'm not sure if that would work for writing. I haven't had a chance to look into the details of file system implementation. I'm pretty sure that the substr is faster than the regex (although not by an order of magnitude or anything like that) , and it will work. It will suffice for now, but I was hoping to at least find a way where I wouldn't have to read the string into memory twice, which is what I'm guessing my implementation above will do.
Ideally, I'd like to read it into memory once and then create a string that is a pointer to the two pieces and the new inserted piece (or something like that), and not have to think about the implementation thereof.
I'm also curious if I use substr, if the full string is read into memory or just the portion required. Also, I'm curious when the stack is used vs the heap, etc.
I know I could look at the Perl source and get specific answers, and will probably do that at some point; however, I was just hoping to get a quick answer as to a good (simple) way to handle it efficiently. If using files or some other mechanism would be better and could also be done as a one-liner, that would be great to know also.
Eventually, I will probably rewrite the parser using a compiler compiler and C or C++. Still, perl seems to have some good features that might port over well and be usable as a library, so I'd like to put a little time into learning it better.
If using substr as above is the most efficient, simple way of handling big strings, that is great to know too. (Also, it'd be great to know if there is a better, but still simple, way than using big strings to perform large file manipulation, etc.)