Trap 2 - a solution 

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