in reply to Replace $a with $b if $a ne $b

It's almost indentical to your subject:

Replace $a with $b if $a ne $b
$a = $b if $b ne $a;

which simplifies to:

$a = $b;

Or maybe you wanted

$a = $b unless $a =~ /$b/;