Hello I am trying for an hour now, > p <- "c:/data/" or > p <- "c:/data/abc.hig" d <- sub("(.+/.+?/)(.+)","\\1",p,perl=TRUE) f <- sub("(.+/.+?/)(.+)?","\\2",p,perl=TRUE) if (exists("f")){ #why this gives TRUE no mater what? do this with d and f } else { do that with d } thanks