my $file = 'Events.txt'; open $info, "<", $file or die "Couldn't open events file: $!"; open $xml, "<", 'XML_FILE.xml' or die "Couldn't open xml file: $!"; open $output, ">", 'OUTPUT.txt' or die "Coudn't open output file: $!"; my $found = 0; #Flag for indication while(my $line = <$info>) { @get_data = split ',' ,$line; $alert_ID = $get_data[5]; seek $xml, 0, 0; # Seek to the beginning, to scan from beginning for each ID. while(my $xml_line = <$xml>) { if ($xml_line =~ m|$alert_ID|) { $found = 1; last; } } if ( $found == 1 ) { print "$alert_ID Found.\n"; $found = 0; } else { print $output "@get_data"; } } close $info; close $xml; close $output;