FILE: for my $file (@update) { my $first_4_chars = substr($file, 0, 4); next FILE if not $seen{$first_4_chars}; copy($file, "$to_dir/$first_4_chars"); }