#!/usr/bin/perl use strict; use warnings; my $regex = qr/(foo)(bar)(foo)/; my $hit = 2; # geht natürlich nicht # mehr Code my $bla = "foobarfoo"; if($bla =~ m/$regex/){ no strict 'refs'; print ${$hit}; }