#!/usr/bin/perl use strict; use warnings; # Read barcodes, and look for coresponding files to rename my $dir = "/samplesA"; my $bcf = "/ID.txt"; open my $barcodelist, "<", $bcf or die "Can not open barcode file $bcf: $!\n"; while (my $line = <$barcodelist>) { chomp; my ($id, $barcode) = split(/\t/,$line); # I like validating inputs warn "bad line at $.\n" unless $barcode =~/^[ACGT]+$/; my $file = "$dir/sample_$barcode.fq"; if (-e $file) { my $new = "$dir/$id.fq"; rename $file, $new or die "Can't change $file to $new, $!\n"; } } close $barcodelist;