First, you should not be using variables $a and $b because these are magic variables used in
sort. More importantly they are probably meaningless in your context.
Anyway, you
might be better off using a regular expression (RE) to check patterns rather than literal values. I say 'might' because it really depends on the application, and REs can be slow. This is a balance decision which only someone with complete knowledge of the application can make.