# your data is in %tag open (IN, "Result_file.txt") or die "Cannot create file $!\n"; while () { print OUT $_ if exists $tag{$_}; }