#!/usr/bin/perl use strict; use warnings; my $text = 'Mary had a little lamb.'; # get your text from wherever my $regex = 'it'; # get your regex info from wherever my $reg = qr/$regex/; # compile it print $regex if $text =~ $reg; # check for a match