for (qw(a b)) { /(a)|(b)/; print( defined($1) ? $1 : '~', defined($2) ? $2 : '~', "\n" ); }