Refactor code to check if $PATH contains a pattern