class Ideone {
    static void main(String[] args) {
		String s = "hey where.is.the book on.brown.table\nhey there.is.a.boy.in.the city Delhi\nhey here.is.the.boy living next door"
		print s.replaceAll(/(\G(?!\A)\w+|\b(?:where|there)\b)\./, '$1_')
    }
}
