in reply to Deleting specified files and directories

unlink will operate on files in the current directory, if you haven't provided a fully-specified path when calling it. Try:
foreach my $file (@onlyfiles) { unlink "$basedir/$mesgdir/$file"; }
Also, you will be virtually tarred and feathered unless you use strict, turn on warnings (#!/usr/bin/perl -w), and check for errors after system calls (such as opendir).
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print