If all you want to do is add the header (meta info) to every hit, this can probably be done in two very simple lines of code: always store the current (latest) header and add it to the results.
If you do the main data lookup line by line with a while loop or similar construct and supposing that no line has more than one <text> tag pairs (i.e. new texts are on new lines) and the opening and closing text tags are always on the same line (i.e. there are no line breaks within the header), something like this should work:
while (<FILE>){
if (/<text>(.*)<\/text>/) {$currentheader = $1} # if the current line
+has a header, save it, otherwise, keep last saved header
# your data search code goes here
if (there was a hit) {print $currentheader along with the hit}
}
This way you only go through the file once. Of course this may not be doable if you use some exotic solution for your search word matching instead of a while loop.
Edit: I just noticed that chrestomanci already proposed a more elaborate execution of the same idea.