# We'll pass it as ref to SCALAR and receive it in a ref to ARRAY use constant ARTICLES => 100; use constant ENTRIES => 2000; #Articles foreach $article ( 1 .. ARTICLES ) { foreach $feature ( 1 .. 10 ) { $A->{$article}{$feature} = int rand(100); } } #Entries foreach $entry ( 1 .. ENTRIES ) { foreach $feature ( 1 .. 10 ) { $E->{$entry}{$feature} = int rand(100); } } $| += 1; foreach my $article ( 1 .. ARTICLES ) { foreach $entry ( 1 .. ENTRIES ) { # print "." if $entry % 1000 == 0; my $count; foreach $feature ( 1 .. 10 ) { if ( $E->{$entry}{$feature} eq $A->{$article}{$feature}){ $count += 1; } } if ( $count >= 3 ) { #Found match push @{ $X->{$article} }, $entry; } } } foreach my $article ( sort { $a <=> $b } keys %{$X} ) { print "$article:"; foreach my $entry ( @{ $X->{$article} } ) { print "\t$entry"; } print "\n"; }