in reply to Passing a filehandle to subroutine

Here is a simplified SSCCE which hopefully shows that your SubOut as written will exhaust the passed filehandle. If that isn't what you want it to do then you will need to change the algorithm in SubOut().

use strict; use warnings; use Test::More tests => 4; open (F, "echo -e 'a\nb\nc'|"); my $line = <F>; is ($line, "a\n", "a in main()"); while ($line) { if ($line =~ /a/) { SubOut (\*F); } ok (eof (F), "F is exhausted"); $line = <F>; } close (F); sub SubOut { my $fh = shift; my $s_line = <$fh>; while ($s_line) { like ($s_line, qr/[bc]\n$/, "b or c matched in SubOut()"); $s_line = <$fh>; } }

Note, this was tested on Linux. Results on non-unixy platforms may differ. Caveat emptor.