in reply to perl one liner

Almost. You need to do the substitution after the assignment, not assign the results of the substitution:

($var2 = $var1) =~ s!/!!;