use strict; use warnings; my $text = "josdifj34joji"; my $regex = '(\d+)'; my $opt = "g"; my $erg=undef; my $com = '$text =~ m/'."$regex".'/'."$opt;\$erg=\$1"; eval $com; print "\$1: $erg\n";