#!/usr/bin/perl -w $text = "josdifj34joji"; $regex = '(\d+)'; $opt = "g"; $com = '$text =~ m/'."$regex".'/'."$opt;"; eval $com; print "\$1: $1\n";