while ( $text =~ m/\b($words_re)($words_re)\b/gi) { my $word1="\u$1"; my $word2="\u$2"; print "$word1 ->" , $hash{$word1},"\n"; }