$pat = File::Spec->catfile($HomePath, ''); if ($Model =~ m/^\Q$pat\E/i) { (undef,$WorkingDirectory,undef) = File::Spec->splitpath($'); } else { # whatever to do if the supplied variable isn't under $HomePath }