my $host = lc(shift(@_)); #### my @lines = grep { lc($_) eq $host } @ry; #### use List::Util qw( first ); my $line = first { lc($_) eq $host } @ry; #### use List::Util qw( first ); my $line = first { lc($_) eq $host } <$fh>; #### sub get_comments { my $host = lc(shift(@_)); my $file_name = "myfile.txt"; open(my $fh, '<', $file_name) or die("Unable to open server info file \"$file_name\": $!\n"); while (<$fh>) { return $1 if /^$host:\s*(.*)/; } return; }