/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.regex.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String s = "word 123 some text inside next 567";
		StringBuffer result = new StringBuffer();
		Matcher m = Pattern.compile("(\\w+)\\s+(\\d+)").matcher(s);
		while (m.find()) {
    		String wrd = m.group(1);
    		String num = m.group(2);
    		String replacement = wrd.toUpperCase() + num;
		    m.appendReplacement(result, replacement);
		}
		m.appendTail(result);
		System.out.println(result.toString());

	}
}