in reply to code help

Why are you trying to do it in one select? Just (prepare one and) execute three selects and keep the first one which is not in the table. See the DBI docs (or Super Search this site) and use placeholders/bind values. Its as easy as:
my $new_name; for my $name ($name1, $name2, $name3) { $new_name = $name; $sth->execute($name); $sth->fetch or last; $new_name = ''; } print "New name: $new_name" if $new_name;