use strict; sub filegrep { ... } my @files = filegrep('Match this!'); #### sub filegrep { # 1 2 3 4 5 #12345678901234567890123456789012345678901234567890123456 my@k;for(<*>){open F,$_;push@k,$_ if grep/$_[0]/,};@k }