my $r = $sth->execute(values %sql_data) or die "execute failed"; if ( $r == 0 ) { # do the insert }