while (defined($file = readdir(DIR))) { next unless $file =~ /^(abc)(\d{1,3})(\.html)$/; rename "$dirname/$file" "$dirname/" . $1 . "0" x (4 - length $2) . $2 . $3; }