$ perl -i.bak -pe 's/ / /g; END {unlink "*.bak"}' file.txt #### perl -i.bak -pe "s/ / /g; END {unlink qq/*.bak/}" file.txt