jwkrahn is right that the 'g's are superfluous. But I don't think that is the core of the problem. Indeed, if that had been the problem, the match would have always failed. You are invoking s///g in a void context, not a scalar one. Indeed, after a mild cleaning of your code, I can't reproduce the problem as described:
prints#!/usr/local/bin/perl -w use strict; my @files =qw(CQA_frobbish.OUTPUT cQa_blintz.output cqA_pmos_lkg.outpu +t); my $ModNameList = 'pmos_lkg'; foreach my $file ( @files ) { if($file =~ m/.output/gi ) { my $name = $file; $name =~ s/.output//gi; $name =~ s/^cqa_//gi; if($ModNameList =~ m/$name/g) { print "Found:$name\n"; } } }
Some other comments on your code:Found:pmos_lkg
use strict; foreach (@files){ my $name2; if(($name2) = / ^cqa_ # Starts with cqa_ (.*) # Here's the namestring we want \.output # and the right file extenstion $/xi # and nothing else. and $ModNameList =~ /$name2/){ print "FOUND: $name2\n"}}
In reply to Re: Pattern Matching Failing
by throop
in thread Pattern Matching Failing
by upallnight
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |