sub insert_entry { my $table=$_[0]; #table my $col=$_[1]; my $entry=$_[2]; #value my $insert=sprintf(qq(INSERT INTO %s(%s) VALUES(%s) ON DUPLICATE KEY UPDATE id=LAST_INSERT_ID(id)), $dbh->quote_identifier($table), $dbh->quote_identifier($col), $dbh->quote($entry)); my $sth=$dbh->prepare($insert); $sth->execute(); if ($sth->last_insert_id()){ #if new insertion return; } else { return $sth->last_insert_id(); #if duplicate return key } }