use strict; use warnings; use Data::Dumper; my %hash = ('Abend' => 'NN', 'Sonne' => 'NN', 'Haus' => 'NN', ); my $text="Haus Abendsonne haussonne hurz"; my $words_re= join '|', keys %hash; my @komposita= $text =~ m/\b(?:$words_re)(?:$words_re)\b/gi; print Dumper \@komposita;