Your parsing errors result due to different things:
- You have to escape the \ in the regexp. \d has a special meaning (a digit) within a regexp, \t is a tab and so on, so you have to double the \ in your substitute, too.
- You should not use .* at all. Please read Death to Dot Star! for more information on this. In here you like to replace it with [^\\]* to match everything except an \.
- You were missing the s infront of the substitute you liked to do.
- In your assignment to $Pdir and $Sdir you did forgot that you want to match $parentdir, and the $1,$2 at the end is, uhm, simply wrong.
Your code might look like this:
# I dislike having to escape everything when I can use '' instead
$path = '\default\main\Anand\toipcs\Tutorials\internet';
$curPath = $path;
$curPath =~ s!\\default\\main\\([^\\]*)\\Tutorials\\internet!$1!;
$parentdir = $curPath;
print "parent Directory : $curPath\n";
($Pdir,$Sdir) = $parentdir =~ m!([^\\]*)\([^\\]*)$!;
print "parent branch : $Pdir \t sub branch $Sdir";
HTH & HAND,
--
use signature;
signature(" So long\nAlfie");