http://www.perlmonks.org?node_id=938729


in reply to string match using with an N in any position

You could probably do something like this:

# reading in each query string (file1) into an array my @barcode; while ( my $line1 = <INP1> ) { chomp $line1; my @temp = ( $line1, ( $line1 ) x length $line1 ); substr $temp[ $_ ], $_, 1, 'N' for 0 .. $#temp - 1; local $" = '|'; push @barcode, [ $line1, qr/@temp/ ]; } for my $code ( @barcode ) { my $filename = $code->[ 0 ]; open OUT, '>', $filename or die "Cannot open '$filename' because: +$!"; # I have stored each of the query strings in a hash. # The value of the hash contains the target strings. # The keys are 1,2,3... for my $value ( values %idhash ) { if ( $value =~ /^$code->[1]/ ) { # where the query string matches the target # string print value of the hash print "$value\n"; } } }