my $regex = qr/(foo)(bar)(foo)/ # mehr Code if($bla =~ m/$regex/) print $2; # mehr Code if($blub =~ m/$regex/) print $2;