$de =~ s([^a-zA-Z0-9 _/\.-])()g; #strip everything that's not approved. $de =~ tr(./)(./)s; #Look for repeats of the . and / and squash them. $de =~ m/(\w+.*)$/; #Strip off leading . and / just in case. $de = $1;