in reply to filtering readdir()'s results

You have to read all the filenames. However you can filter out the files whose names you are interested in. grep would be a good choice for this.

--
perl -wpe "s/\b;([mnst])/'$1/g"