#!/usr/bin/perl -w use strict; use 5.6.1; sub find { local *FH = shift; my $find_me = shift; my $count = 0; my $tell = tell(FH); while () { $count++ if (/$find_me/); } return "count: $count tell: $tell\n"; } open OUT, '>', '/tmp/tmp.txt' or die "$!\n"; print OUT while (); close OUT or die "$!\n"; open IN, '/tmp/tmp.txt' or die "$!\n"; print find( *IN, 'a' ); print find( *IN, 'a' ); print find( *IN, 'd' ); print find( *IN, 'e' ); #count: 3 tell: 0 #count: 0 tell: 13 #count: 0 tell: 13 #count: 0 tell: 13 __DATA__ a a a c d e