in reply to untarring number of files
system('tar -xvf $file');
should quote the filename:
system(qq(tar -xvf "$file"));
to protect against spaces. This is not perfect; it doesn't protect against doublequotes in the filename.