in reply to thanks, i'm new. rtfm right? :)

Don't bother with the system call(s):
opendir
readdir
closedir
grep
and maybe: File::Basename (ok, maybe not)
and you can strip off a fixed string like '.txt' with substr even though a regex looks cooler (and I admit is more self-documenting) as others have shown. I don't get whether you just want to process '.txt' files or you want to strip extentions off of all files. I'd build a list of all the files (grep'ing just the '.txt' files?) then grep the $count from the list each time, or order the list by the implied $count in the files, and process the list in order.