in reply to Regex with variables

Some additional thought:

Where does the data format come from? Is it guaranteed you will always be matching a 4-digit-number against other 4-digit-numbers?

I guess the safe bet would be to go for the hash-based solution that was already recommended. That way you can also match different sized values and do not need to fear accidentally matching 210 against 2102. (Bugfix: Modify regexp to include whitespace. Bugfix to the bugfix: properly handle first and last value in $targets...)

But it's also possible the regexp-solution is actually better suited to your need. Consider your options and pick wisely. ;)