I see two things.
1) The $mh variable has all of the files in the directory, so if you only have one, your code will work, but if there is more than one file, with any name, in the directory, you will need to add a loop, i.e.,
foreach file $data {
The rest of your stuff to process a single file.
}
2) It looks like you have the foreach loop a little later on, and it may be as simple as moving that foreach command up in the proc just after msgget command.
Hope this helps,
Bob 8)
Robert Milfajt
Northwestern Medicine
Chicago, IL