foreach $word( @termList ) { if ( exists( $hash{ $word } ) ) { # Record occurrence of term } } #### foreach $word ( keys $termHash ) { $document =~ s/$word/$termHash{ $word }/g; }