$variable =~ s/$tofind(?![$tofind])$/$replacement/;