#!/usr/bin/perl -w use strict; use warnings; use File::Basename; sub remove_files_in_empty_directories($) { my ($directory) = @_; # do nothing if the directory is not empty # This is the problematic part return if glob("$directory/*"); # directory is empty, remove the .Ecurep-Lenovo* files foreach my $file ( glob("$directory/.EcuRep-Lenovo_*") ) { print $file,"\n"; } } my $list_file = shift @ARGV; die "list_file is missing - Usage: $0 list_file\n" unless $list_file; open(F,"<",$list_file) || die "can not open $list_file: $!\n"; while (my $line = ) { chomp $line; my $dir = dirname $line; remove_files_in_empty_directories($dir); }