in reply to Substitute $a with $b only when a is not followed by $c

You want to use a negative look-ahead assertion (as described in 'perlre'):
$string = "123456123789"; $a = 123; $b = "abc"; $c = 456; $string =~ s/$a(?!=$c)/$b/;
That sets string to "123456abc789". (?=...) is a positive look-ahead, (?!=...) is a negative look-ahead. (?<=...) is a positive look-behind, (?<!...) is a negative look-behind.