sub find_avaliable { # Create the SQL statement $sth = $dbh->prepare( "select CODE from INV where CODE = $user_input"); # Execute the SQL statement and generate a result set $sth->execute(); #Get results and process ($CODE) = $sth->fetchrow_array; if ($CODE ne "") { $user_input+=1; &find_avaliable; } else { #$COUT->Write("$user_input"); return; } }