$fileName = 'viper'; $main::mailTemplate = '/main/etc/mailtemplate.txt' $main::outputDir = '/main/attachments'; $main::delAddress = 'abc@gmail.com'; chdir $main::outputDir or die "can't cd"; @files = `ls|grep $fileName`; foreach(@files) { $main::delFileName = $_; print $main::delFileName; #prints the correct file name my $result = `cat $main::mailTemplate|mutt -s "TITLE OF MAIL" -a $main::outputDir\/$main::delFileName $main::delAddress`; }