... my $pattern_to_find = '4567'; ... while () { my ($pattern, $id) = (split /\s+/)[0, 2]; ... if ($pattern eq $pattern_to_find) { ...