in reply to weighting regex patterns

This isn't an answer to your question per se, but I just wanted to make sure you are aware of Bioperl, which may or may not be useful for this (or other things you are doing).

As for your question, what data structure do you have your 'matrix' in? How is it being represented in your program? I guess I don't understand your problem. I would think a hash would help you with this (but I may be wrong).

my %dna = ('nucleotide1' => {A => 25, T => 25, G => 25, C => 25}, 'nucleotide2' => {A => 10, T => 15, G => 50, C => 25}, etc... );
Then you could do:

$dna{nucleotide2}->{T};

Which would give you the weight (15 in this case).

Cheers,
KM