I try to use a specific word in my file to put it as a folder name.
This word vary in my file so, I think about use regular expressions to define it.

my $file=$ARGV[0];
my $word=~/DOT\d+/;
my $line="";

open(file, $file);

while( $line = <file>){
    if ( $line =~ /^Number\s=\s$word/){
        unless(-d $word){
            mkdir $word,0755;
            chdir $word or die "can't change directory";

close GSE;

Unfortunately, that doesn't work.

Can Perl understand regular expressions in a variable and understand a regular expression in a regular expression?

Thanks for help,

my $word=~/DOT\d+/; attempts to match whatever is in $word and there is nothing in $word at this point in the script.

You can store a regex pattern in a variable using the Regexp-like quote function as follows: my $word = qr(/DOT\d+/);

Sorry, the above example of using qr to store a pattern is not quite correct. You could store your pattern as follows:
my $word = qr(DOT\d+);

For example:

use strict; 
use warnings;

my $string = 'Number = DOT123';
my $word = qr(DOT\d+);

if ($string =~ m/^Number\s=\s$word/){
    print "$string matches the $word pattern\n"
    print "$string does not match the $word pattern\n"

I will try this as soon as possible and give you a feedback. Thank you d5e5.

So great! I successed in my job thanks to these Extracting Matches. Very simple in fact. Thank you again Mr d5e5!

This question has already been answered. Start a new discussion instead.