my $entries; while () { chomp; my($ip, $text) = split /\s+\|\s+/; $entries{$ip} = $text; } print $entries{"192.168.0.1"}; # some text __DATA__ 192.168.0.1 | some text 192.168.0.2 | another text