Let $R$ be a ring and $A(R)$ be an appropriate subset of $R$. In this paper, it is shown that $R$ is commutative if and only if for every $x,y\in R$, there exist integers $m=m(x,y)>1$, $n=n(x,y)\geq0$ such that $[x,x^ny+y^mx]=0$ and for each $x\in R$ either $x\in Z(R)$, the center of $R$, or there exists a polynomial $f(t)\in Z[t]$ such that $x—x^2f(x)\in A(R)$, where $A(R)$ is a nil commutative subset of $R$. If $R$ is a left or right $s$-unital ring, then the following are equivalent: (i) $R$ is commutative. (ii) For every $x,y\in R$, there exist integers $m=m(x,y)>1$, $n=n(x,y)\geq0$ such that $[x,x^ny+y^mx]=0$ and for each $x\in R$ either $x\in Z(R)$ or there exists a polynomial $f(t)\in Z[t]$ such that $x-x^2f(x)\in A(R)$, where $A(R)$ is a nil subset of $R$. (iii) For each $y\in R$, there exists an integer $m=m(y)>1$ such that $[x,x^ny+y^mx]=0=[x,x^ny^m+y^{m^2}x]$ for all $x\in R$, where $n\neq 1$ is a fixed non-negative integer.