my $wanted = sub { $name =~ /\Q($wrong_dir\E)(.*)/ or do { warn "Can't match $name for $wrong_dir in line __LINE__.\n"; return undef; }; my $the_thing = "$correct_dir$2"; if (-e $the_thing) { cpmod2($the_thing,$name) or die "just couldnt do it: $!\n"; } };