$ perl -Mstrict -Mwarnings -E ' my @source_data = ( ["Archeologist", "Ancient projects", "Cairo"], ["Architect", "Major projects", "London"], ["Architect", "Small projects", "Sydney"], ["Architect", "Small", "Hong Kong"], ["Programmer", "Big", "Hong Kong"], ); my @search_data = ("Architect", "Hong Kong", "Small"); my @found_data; my $re = "(?:" . join("|", @search_data) . ")"; for (@source_data) { my $matches = 0; /$re/ && ++$matches for @$_; push @found_data, [$matches, $_] if $matches; } say "@{$_->[1]}" for sort { $b->[0] <=> $a->[0] } @found_data; ' Architect Small Hong Kong Architect Small projects Sydney Architect Major projects London Programmer Big Hong Kong