opendir(DIR,$destinationdirectory) or die "Could not open $destinationdirectory because $!\n"; foreach (my $zips = readdir(DIR)){ ($txt = $zips) =~ s/\.log$/.txt/i; unless(rename($zips, $txt)){ warn "could not rename $zips to $txt because $!\n"; next; } }