use Regexp::List qw( ); my $re = Regexp::List->new(modifiers => 'i') ->list2re( map lc($hash{$_}[0]), keys %hash ); # or: # my ($re) = map qr/$_/i, # join '|', # map quotemeta(lc($hash{$_}[0])), # keys %hash; while (my $cur_line = <$fh_log>) { while ($cur_line =~ /($re)/g) { my $table = lc($1); if ($tables{$table}) { # Count up how many times this table is referenced. $table_stats{$table}++; $table_refs++; } } }