foreach $row (@{$list}) { my @matching = map { String::Approx::amatch($row->[$_+1],$vals[$_]) ? $_ : () } (0..$#vals); return (@matching==@vals) ? $row[0]; } # none found; do the insert, get the new id and return it