one=1 two=2 three=3 xyz=20 #### one=1 two=2 three=3 xyz=21 #### perl -p -i.bak -e 's/$1/$a/ if ((/xyz\s*=\s*([0-9]*)\s*/)&&($a=$1+1))' test.data
## one=1 two=2 three=3 xyz=21 ##
## perl -p -i.bak -e 's/$1/$a/ if ((/xyz\s*=\s*([0-9]*)\s*/)&&($a=$1+1))' test.data