perl -pe 's/(.*\\$target\\)[^\\]*\\(LATEST)/$1$2/;' yourfile