use strict; use warnings; my %hash; while(){ my ($key, $value) = split(/\s+/, $_); $hash{$key} = $value; } foreach(keys %hash){ if ($_ =~ /this|is|a|test/){ print "found string \"$_\" and its value is \"$hash{$_}\"\n"; } } __DATA__ this 1 is 2 a 3 test 4