opendir/readdir is the wrong set of things to call for what you described. You want to "open" the file (I usually call it F if it's the only input file), then
while (<F>) {
while (/\G(timepattern)/g) {
print FILE $1, "\n"
}
}
If you are supplying the file name on the command line, change "while (<F>)" to "while (<>)".
The inner while loop searches for all the substrings that match the regexp timepattern on an individual line. If you know there is at most one match for timepattern on a line, the inner "while" becomes "if (/(timepattern)/)". Constructing timepattern is a valuable enough skill that you should expend the effort to learn it on your own; see the perlre manpage. Or, as the textbooks say, it is left as an exercise for the reader.