First of all, you probably don’t want to process your data as “arrays,” i.e. “memory,” simply because memory is virtual. The cause of your excessive completion times is undoubtedly caused by virtual-memory thrashing, which is known to “hit the wall” with exponential (not linear...) performance degradation.
I would suggest that you put the data into an SQL database ... or, perhaps, an SQLite database (which is actually a single disk file). (Remember to use transactions when using SQLite...) You could now write scripts to extract the elements you’re interested in, dumping these into another table (e.g. with fragment_text and some primary-key element_id field). Now, the remainder of your task (and of any tasks similar to it) has devolved into an SQL JOIN which doesn’t even require any further programming at all. (So what if the SQLite file is hundreds of megabytes ... SQLite isn’t bothered by such trivial concerns.)
Are you posting in the right place? Check out Where do I post X? to know for sure.
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
Want more info? How to link or
or How to display code and escape characters
are good places to start.