in reply to Re^2: Print text on the same line after match
in thread Print text on the same line after match

Is there a better way to store the result into the variable?

Yes - I showed how to do this without calling an extra perl process, it'll give you much more power and control.