in reply to perl one liner
Do the assignment and substitute thereafter:
($var2 = $var1) =~ s!/!!; [download]
The substitution above operates on $var2.