while() { chomp; if(//i) { $sessionID{$4} = 1; } } #### open(MSG) or die("couldn't open msg log"); while() { chomp; if(my ($id) =~ /)>/i)) { push @matching_lines, $_ if $sessionID{$id}; } } close(MSG); print $_, "\n" foreach (@matching_lines);