simplified the regexes in the sed
removed unnecessary quotes
renamed OLDPWD to oldpwd to avoid messing with the *real* OLDPWD
replaced sed with perl for the -si case