if ($Path =~ m{^(.*)\/([^\/]*)}) # if whatever-is-in-$Path matches that pattern, # which should imho better be written as # m{^(?:([^/]*/)+([^/]*)} { # then $Dir is "the whole thing before the last slash" # when you use my pattern, you'll have to chop() it $Dir = $1; # $File is averething after the last slash $File = $2; # $Ext will always be undef $Ext=$3; } else { # otherwise the $File is the whole $Path $File = $Path; } # next part if ($File =~ m{^(.*)\.([^\.]*)}) # again "death to dot star": # m{^([^.]*.)+([^.]*)} { # if that one matches, $File is everythin before the # last dot # $Dot becomes '.' # $Ext is everything after the last period $File = $1; $Dot = "."; $Ext = $2; } else { # otherwise $Dot and $Ext are empty strings $Dot = ""; $Ext = ""; } # next part if (-d "/$Dir/$File") # if "whetever results when you join $dir and $file with # a slash and preceed it by another slash" truns out to be # resolved as directory { # then $File, preceeded by slash, is appended to $Dir $Dir .= "/$File"; # and $File becomes an empty string $File = ""; }