my %testar = ( 'reg1' => qr~\Q/var/logs/logger/\E(?:\d*)/(\d*)~, 'req2' => qr~...~, ); my ($wantedField) = $string =~ $testar{'req1'};