# list of items in list context, first item in scalar. sub matching_things { my( $input_iter, $pat ) = @_; my @things; while ( <$input_iter> ) { /$pat/ or next; wantarray or return $_; push @things, $_; } @things }