http://www.perlmonks.org?node_id=210421

   1: #!/usr/bin/perl
   2: #rembak.pl
   3: #it is useless, but i like Perl to do things for me (-:
   4: 
   5: use Getopt::Long;
   6: 
   7: my $verbose_mode = '';
   8: GetOptions('verbose' => \$verbose_mode);
   9: 
  10: $dirname = `pwd`;
  11: chomp $dirname;
  12: 
  13: $counter = 0;
  14: open(SIN, "ls *~|") or die "Unable to read list of files!\n";
  15: 	while(<SIN>){
  16: 		chomp;
  17: 		system("rm -f $_");
  18: 		if ($verbose_mode) { print "\t$_ deleted.\n"; }
  19: 		$counter++;
  20: 	}
  21: close SIN;
  22: print "I have deleted $counter backup files in directory $dirname.\n"