As many of the posts have been mentioned, using `ls`, files with spaces will be split into multiple tokens. If you use any of the suggestions from above to actually read in the lists of files to use (ie, do it from in perl, use * globbing, use find), then $file will contain the correct data.