my $new = $file; if ($new =~ s/sample_$barcode/$id/) { rename ($file, $new) or die; }