http://qs321.pair.com?node_id=204318


in reply to Getting a Regex Not to Match Again

I don't think that this:
my $cmd1 = "/bin/mv /etc/$i.d/$name /etc/$i.d/.NO.$name" or print "/etc/$i.d/$name not found\n"; `$cmd1` if $name =~ /\b(K|S)\d{2}?$expression\b/;
Does what you are expecting... It looks like you think $cmd1 will be some sort of "command" that when used in the backticks will either move the file or print your message if it fails. To achieve this, you're better of using Perl's builtin rename command:
if ($name =~ /^[KS]\d{2}$expression$/) { rename "/etc/$i.d/$name", "/etc/$i.d/.NO.$name" or print "/etc/$i.d/$name not found\n"; }
Notice that I used the modified regex as suggested by sauoq.

In case you're wondering, the first line of your code that I quoted above does this:

  1. Interpolate the variables $i and $name into the string "/bin/mv /etc/$i.d/$name /etc/$i.d/.NO.$name"
  2. Assign the result of the interpolation to the variable $cmd1
  3. If the return value of the assignment is false, print "/etc/$i.d/$name not found\n"

The return value of an assignment expression is the value assigned (isn't that a mouthful). Since the interpolation you're doing will never have a false value (i.e. it will never interpolate into "" or 0), the return value of the assignment will always be true and the print statement will never be executed.