my $h = { hello => [ 1, 2, 3, 4 ], world => [ 5, 6, 7, 8 ], }; my $str = 'Hello World, Just another hello hack!'; for my $word( split /\W+/, $str ) { my $key = lc($word); my $mapping = exists $h->{$key} ? $h->{$key} : [ '#???#' ]; print "$word\t@$mapping\n"; } __DATA__ Hello 1 2 3 4 World 5 6 7 8 Just #???# another #???# hello 1 2 3 4 hack #???#