#!/usr/bin/perl use warnings; use strict; my $regex_number = qr/(\d+)/; if ( "Hallo 10 Welt" =~ m/$regex_number/ ) { print $1, "\n"; }