While searching something on net I found an interesting method of groovy collectReplacements. This method iterate through the string character by character and replace the matching character with the given string. This method take closure as an argument.

assert "Groovy".collectReplacements { it == 'o' ? 'O' : null } == 'GrOOvy'

Here you can also have multiple conditions like

def replace = {
            if (it == 'j') {
                'J'
            } else if (it == 'f') {
                'F'
            } else if (it == 't') {
                'T'
            } else if (it == 'b') {
                'B'
            } else {
                null
            }
        }

assert "jft blog".collectReplacements(replace) == 'JFT Blog'

Also we can achieve the same result via switch cases.

assert "mkb".collectReplacements {
            switch (it) {
                case 'm':
                    'Manish '
                    break
                case 'k':
                    'Kumar '
                    break
                case 'b':
                    'Bharti'
                    break
                default:
                    null
            }
        } == 'Manish Kumar Bharti'

Note:- Closure should return null to indicate no transformation is required for the given character.

Note:- I have tested it on grails 2.3.0(groovy 2.1.6).