if ( $t =~ m{(\d+) foo} && $t =~ m{$lookup{$1} bar} ) { print "matched.\n"; }