6. Delete files

Use unlink to delete a file:

$ perl -e '$file_to_delete = "file.txt"; unlink $file_to_delete or die "Unable to unlink $file_to_delete: $!";' 

6.1 Glob and unlink

To remove e.g. .txt files from the current directory, write

$ perl -e '@files=glob("*.txt"); unlink(@files);'

6.2 Readline and unlink

To remove the files described in list_files.dat, write

$ perl -e 'open(FH, "list_files.dat") or die("Unable to open file.");@data=<FH>;close(FH);chomp(@data); unlink(@data);'
Lines read from a file with the readline operator (<...>) will include the newline character. You'll need to remove it. Perl's chomp function does the job.