my $dbh = DBI->connect( "DBI:mysql:database=$db_name;host=$DB_HOST;mysql_client_found_rows=1", "$DB_USER", "$DB_PASS" ) or die $DBI::errstr; my $rows = $dbh->do(qq~ update mytable set myvalue = ? where mykey = ? ~, undef, $myvalue, $mykey ) or die $DBI::errstr; if ($rows == 0) { # no record updated, so we insert new one $dbh->do(qq~ insert into mytable values ( ?, ? ) ~, undef, $mykey, $myvalue ) or die $DBI::errstr; }