Use my solution to your question
How do I remove the subdirectories from the directory struture using Perl?[
^] as starting point (
untested EDIT: tested and fixed errors):
sub DelTaskFiles{
my ($workdir) = shift;
my $mask = $workdir . '/*';
my @files = glob $mask;
foreach $f (@files)
{
if (-d $f)
{
DelTaskFiles($f);
}
else
{
my $filename = basename($f);
if ($filename =~ /^task/)
{
unlink $f;
}
}
}
}
DelTaskFiles('/home/rpasa/demo_checklist');
}
General rule:
If you need to process subdirectories use a recursive function that processes the directories. In each directory iterate over the files and perform the required action for matching files.