I'm trying to figure out how to do a replace on a string using a regular expression with a variable. The catch is, it should only perform the replace if the string has white space surrounding it. My current regex s/(\Q$user\E)/xxxxx/g is a bit too greedy and ends up replacing instances it shouldn't. An example would be if $user is lee I would want to replace any instance of lee but not lee in leeroy.