my %options=(); getopts('c:f:', \%options); pod2usage(2) if (keys %options != 1); if($options{c}){ #variable grab my $pattern = qr/$options{c}/; print "Please enter the text you wish to run the pattern on: "; my $text = ; chomp $text; #do work and display if($text =~ $pattern){ print $&; #prints entire match print " " . $text; } else{ print "$pattern on $text Failed. "; } }