in reply to Passing a filehandle to subroutine

A few comments:
#!/usr/bin/perl use strict; use warnings; my $text=<<END; This is an example test file that has xyz line following the matching line 2nd line after the matching line END open my $fh, '<', \$text or die "unable to open text $!"; my @array; while (my $line =<$fh>) { SubOut($fh, \@array, $line) if $line =~ /xyz/; } close $fh; print @array; sub SubOut { my ($fh,$array_ref, $match_line) = @_; push @$array_ref, $match_line; while (my $s_line = <$fh>) { print "$s_line"; } } __END__ Prints: line following the matching line 2nd line after the matching line that has xyz <--- this is in @array