my ( $keeper ) = grep /^Line 3 : /, @lines; #### use List::Util qw( first ); my $keeper = first { /^Line 3 : / } @lines;