#!/usr/bin/perl use strict; use warnings; open my $fh, '<', $0 or die "I can't read myself"; open my $fh2, '<', $0 or die "I can't read myself (2)"; my @lines = <$fh>; close $fh; sub my_sub { my( $this_fh, $line ) = @_; warn sprintf "At offset %d: %s", tell $this_fh, $line; }; while (my $line = <$fh2>) { my @data = my_sub($fh, $line); # copy/paste error, should have passed $second_fh here # and of course a bunch of non-relevant stuff here } __END__ tell() on closed filehandle $fh at tmp.pl line 15. At offset -1: #!/usr/bin/perl tell() on closed filehandle $fh at tmp.pl line 15. At offset -1: ...