thx for your answers.
I need all results where $row == $row1, so "LAST" method dont helps.
also the @c1 and @c2 arrays comes not from mysql queries but from files , which i parsed before. and of coursed my script checks for the same queries.
Then have you thought about using an "in" structure - mssql at least is suprisingly efficient, even when given huge lists - e.g. (cut-down, and untested)
my $list = join ",", @a1;
foreach(@b1){
$sql = "select x from y where v = $_ and z in($list)";
print $sql . "\n";
}