Help for this page
bl123 and barthis123thatqux and barso123quxhim and123som 123
$str =~ s/((?<!bar)\S*)foo((?!\S*qux))/${1}123${2}/gx;
bl123 and barthisfoothatqux and barsofooquxhim and123som 123