Have image move over based on length of text

I am looking to make an image next to text move over if the text is longer. So the layout is simply:

But I have a script that changes the text, and it might not always be the same length. When the text is longer, I want the image to move to the right. I don’t want the size of the image or text to change. I’ve tried looking around and I think I need to use a horizontal layout group but I can’t seem to get it to work as I want it to. Does anyone have any advice?

Are you using Unity UI? you can use anchors and set the image as a child of the text object.