in reply to Parsing a filename

If you used the strictures use strict;use warnings;, you would have seen these warning messages:
Unrecognized escape \D passed through Unrecognized escape \M passed through Unrecognized escape \s passed through

Use single quotes to avoid interpolation:

my $filename_with_path_dos = 'C:\Documents and Settings\My Documents\s +ample.txt';

This prints:

path is /usr/local/sample.txt TEST #1 sample /usr/local/ .txt File is sample.txt TEST #2 path is C:\Documents and Settings\My Documents\sample.txt C:\Documents and Settings\My Documents\sample.txt ./ File is C:\Documents and Settings\My Documents\sample.txt