Maybe it would be possible to split the file into smaller files and run scripts in parallel on the chunks? Of course you would have to compensate for the string lengths:
For example if you want length to be 3 then the last 2 characters in file n have to be combined with the 1st and 2nd characters in file n+1. So for each chunk there will 2 extra strings - except for the last chunk.
Naturally parallel processing is only viable if you have sufficient CPU & RAM.