in reply to identifying arbitury patterns in multiple strings

ditto on JediWizard's reply. in addition, though, i will take a guess that with the two sample lines you're looking for an integer element and want to track what comes before it. Simply match both parts and then store accordingly (below shows how to keep track of just the counts, or in addition to keep the elements themselves too, in which case the count is jsut the size of the array ref)
my %cts; if( $s =~ /^(.*?) (\d+)/ ){ my ($text, $element) = ($1, $2); $cts{$text}++; # OR push @{$cts{$text}}, $element; }