since file url's (like file://c:\test) also work with forward slashses instead of backslashes (file://c:/test/), how about simply replacing all backslashes with a forward slash, and then use the same regex that has been provided by
caedes:
$new =~ s/\\/\//g;
$new =~ s/([^\/])$/$1\//;