if ( substr( $_, 0, length($h) ) eq $h ) #### # we put this in a sub so we can short-circuit via return. # pass headers to search for; # analyzes $_ sub matches_a_header { for my $h ( @_ ) { substr( $_, 0, length($h) ) eq $h and return 1; } 0 } my @matching_records = grep { matches_a_header( @headers_to_find ) } @records;