my $dir = '.'; require File::Spec; opendir my $dh,$dir or die "$dir - $!"; while(defined(my $f = readdir($dh))){ local $_ = File::Spec->catpath(undef,$dir,$f); next unless -f; $f =~ tr/ \t/_/s; my $np = File::Spec->catpath(undef,$dir,$f); rename $_ => $np or warn "rename '$_' to '$np': $!"; } closedir $dh;