Regular Expression - Switch Entire String

I would like to be able to use a regular expression to find and replace entire strings, but not replace if the string is a substring in a larger string.

Example:

$string = "ABC ABCDEF ABC ABCDEF ABC";
Something like - $string =~ s/ABC/XYZ/g;

->Desired:

$string = "XYZ ABCDEF XYZ ABCDEF XYZ";

->NOT:

$string = "XYZ XYZDEF XYZ XYZDEF XYZ";

Is this a homework assignment?

What have you tried?

What shell and OS are you using?

What tool are you trying to use to find and replace strings?

This is perl.
Quick and dirty - use word boundaries!

$string =~ s/\bABC\b/XYZ/g;

Thank you. That solution works great. :):b: