Thank you all for your replies. The full task that I need to perform is to compare all possible sequence pairs combinations (so if I have 3 sequences then I will compare 1-2, 1-3 and 2-3) by sending them to an external program (for which I need only the DNA sequence and not need the header), and then if the comparison meets certain criteria then I save the corresponding headers into an output file (and speaking of which: would it be more time efficient if I keep all the output in memory and then save it to file at the end of run?). I originally used BioPerl which was very convenient, but unfortunately too slow: I really need to try and use memory as much as possible so it will not take months to finish.