foreach (#Loop through the xml file again) { print "$title\n"; print "$content\n"; ... seek $tmpComments, 0, 0 or die "Seek $tmpComments failed: $!\n"; #Rewind temporary comments file while (my $line = <$tmpComments>) { # Split each line, store url as $commentID my @process_comment = split(/~~~/, $line); my $commentID = $process_comment[0]; # If the urls match, add it to the comments variable if ($commentID eq $posturl) { my $commentDate = $process_comment[1]; my $commentAuthor = $process_comment[2]; my $commentBody = $process_comment[3]; $comments.= "$commentDate | $commentAuthor | $commentBody"; } } print $comments; }