in reply to Matching wirth ordered array

Another approach is to remember the length of the longest match "so far" and the corresponding target.
use strict; use warnings; my $string = 'this is a nutrition assessment'; my @dic= ( ['animal source food','aliment d’origine animale'], ['balanced diet','régime alimentaire équilibré'], ['food','aliment'], ['nutrition','nutrition'], ['nutrition assessment','évaluation de l’état nutritionnel'] ); my $longest = 0; my $best_target; foreach my $row (@dic){ my ($TermDBSource, $TermDBTarget) = @$row; my $len; if ($string =~ m/($TermDBSource)/ and ($len = length($1)) > $longe +st) { $longest = $len; $best_target = $TermDBTarget; } } print $best_target, "\n"; OUTPUT: Θvaluation de lÆΘtat nutritionnel

UPDATE: Modified code to be more consistent with original post.

Bill