The above code is wrong, is bad, works sometimes. I know this is wrong.
You didn't say in which way it should be wrong.
It is not wrong, though it might do something different from your expectations.
$sender_transaction_type !~ /3|21/
This is true, if $sender_transaction_type
does not contain the digit 3 or the digit sequence 21.
For e.g. "35" or "421" it is false.
Maybe you expected it to check for equal / not equal, which it doesn't.
But it's not wrong.
To check if a string is not in a given set, you may use this expression:
$sender_transaction_type !~ /^(?:3|21)$/
But keep in mind that these are string operations where "3", "3e0" and "3." are all different, contrary to their numerical equality.