in reply to mark end of variable name (e.g.$1)

s/abc(\w+)x/$1n/; _____ is not working

youre wrong, it works fine