in reply to need help in building dynamic regular expression

See How do I post a question effectively?. You have been told before. You need to wrap code and data in <code> tags so that your posts are legible and so your data does not get corrupted in display.

What have you tried? What didn't work? Post code and we'll help you debug. We aren't here to do your work for you. If this is homework, you are only hurting yourself by not doing it yourself.

Why do you want to use regular expressions? Rather that dealing with all sorts of corner cases yourself, you should probably use File::Spec, one of the core modules. In particular, see splitpath, splitdir and catpath.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.