#!/usr/bin/perl -l my $yo = 'C:/as/d/f/e/r/g/a/d/f/g/'; use File::Spec; print for File::Spec->splitpath($yo); warn $yo; print for File::Spec->splitdir($yo); die $yo; __END__ C: /as/d/f/e/r/g/a/d/f/g/ C:/as/d/f/e/r/g/a/d/f/g/ at - line 5. C: as d f e r g a d f g C:/as/d/f/e/r/g/a/d/f/g/ at - line 7. #### use YAPE::Regex::Explain; die YAPE::Regex::Explain->new(qr/^(\w):\\(.+)\\?/)->explain; __END__ The regular expression: (?-imsx:^(\w):\\(.+)\\?) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ^ the beginning of the string ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- \w word characters (a-z, A-Z, 0-9, _) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- : ':' ---------------------------------------------------------------------- \\ '\' ---------------------------------------------------------------------- ( group and capture to \2: ---------------------------------------------------------------------- .+ any character except \n (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \2 ---------------------------------------------------------------------- \\? '\' (optional (matching the most amount possible)) ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- #### perl -le"print for split m{[:\\/]+}, shift, 3" C:\y\o\d\a C y o\d\a