my $matchStr = join '|', map {$hash{$_}[0]} keys %hash; my $match = qr/($matchStr)/i; while (my $cur_line = ) { #If this query contains reference to this table next if $cur_line !~ $match; #count up how many times this table is referenced. $table_stats{$1}++; $table_refs++; #total table references (for % calc) }