You have to iterate over the directories.
A possible solution:
use File::Basename;
sub ProcessDirectory{
my ($workdir) = shift;
print "Processing '$workdir'\n";
my $mask = $workdir . '/*';
my @dirs = grep { -d } glob $mask;
foreach $d (@dirs)
{
ProcessDirectory($d);
my $dirname = basename($d);
if ($dirname =~ /^temp*/)
{
print " Removing $d\n";
my $filemask = $d . '/*';
}
}
}
ProcessDirectory('/home/rperiasa/output');
Note that I have commented the remove operation so that you can check the operation first.