foreach $row (@{$list}) { for(my ($i=0, $matched=0; $i<@vals; $i++) { if ( $vals[$i] && $row->[$i+1] && String::Approx::amatch($row->[$i+1], $vals[$i]) ) { $matched++; } else { last; } } return ($matched==@vals) ? $row->[0]; } # none found; do the insert, get the new id and return it