while( defined( my $record = get_record( $fh ) ) { # ... } sub get_record { my $fh = shift; join '', scalar <$fh>, scalar <$fh>; } #### A red line is found at location 2.5 4.5