Trap 2 - a solution 

while(my $line = <$fh>) {
  print $line if contains_badger($line);
}
while(defined(my $line = <$fh>)) {
  print $line if contains_badger($line);
}