foreach my $file (glob '/path/*.txt') { (my $new_file = $file) =~ s{txt\z}{html}; rename $file => $new_file; }