use Switch; use DBI; my (@retRows,$retRecs, $searchKey); $searchKey = 'marcC'; $retRecs = test_exists($searchKey,\@retRows); print "returned $retRecs\n"; $tmp = @retRows[0]; print "@$tmp\n"; exit(); sub test_exists { my ($searchKey, $retRowsRef) = @_; my ($retArrayRef, $found); my $dbh = DBI->connect("DBI:mysql:database=aaaaa;host=localhost","bbbbbb","ccccccccc",{'RaiseError' => 1}); my $sth = $dbh->prepare("Select * from sContacts where nKey like '$searchKey%'"); $sth->execute(); $found = 0; while ( $retArrayRef = $sth->fetchrow_arrayref ){ $retRowsRef->[$found] = [ @$retArrayRef ]; $found++; } $sth->finish; $dbh->disconnect; return $found; }