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_')
}
}
Y2xhc3MgSWRlb25lIHsKICAgIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewoJCVN0cmluZyBzID0gImhleSB3aGVyZS5pcy50aGUgYm9vayBvbi5icm93bi50YWJsZVxuaGV5IHRoZXJlLmlzLmEuYm95LmluLnRoZSBjaXR5IERlbGhpXG5oZXkgaGVyZS5pcy50aGUuYm95IGxpdmluZyBuZXh0IGRvb3IiCgkJcHJpbnQgcy5yZXBsYWNlQWxsKC8oXEcoPyFcQSlcdyt8XGIoPzp3aGVyZXx0aGVyZSlcYilcLi8sICckMV8nKQogICAgfQp9Cg==