$HomePath = $ENV{"WORKHOME"}; $Model = shift; $Model =~ m/\Q$HomePath\E\\(.*)\\[.\w]+/i; $WorkingDirectory = $1; #### m/ \Q # Match exact string till \E $HomePath # Start with path from Environment variable \E # End Quote \\ # Backslash (.*) # Working Directory: remember for later \\ # Backslash [.\w]+ # A filename (letters and period) /i # Case insensitive