in reply to array gone amiss

Your script seems to work fine when I throw away all that html stuff.

#!/usr/bin/perl use 5.8.8; use warnings; use strict; my $del= '----------'; my @comments= ('John','Woo',$del,'Karl','Zeiss',$del,'Jehud', 'Menuhin +',$del,'Bjoern','Borg',$del,'George','Bernhard','Shaw'); setText(); my @text=getArray(); my $flipped=flipText(@text); print $flipped; #first, define the subroutines sub setText{ my $commentsString=join ("\n", @comments); open my $writeComments, '>', 'comments.txt'; $commentsString=$commentsString . "\n----------\n"; print $writeComments $commentsString; close $writeComments; } sub getArray{ #you want to return an array from here open my $readComments, 'comments.txt'; my @text1=<$readComments>; close $readComments; my $text=join ('', @text1); #at this point you should have a string, $text, comprised of #your text file, commentsTesting.txt as a string, including #\n's & ----- @text1=split(/----------\n/, $text); return @text1; #so you've put each line into each element of the array, #preserving your newline chars & incl \n's & ---------- #you've translated to a string, $text, via join, incl \n's & ----- #you've translated back into array, (split by -----), where #each section is an element; note ----- are excluded } sub flipText{ my @text1=@_; my @flipped=reverse(@text1); my $flipped1=join ("----------\n", @flipped); $flipped1=$flipped1 . "----------\n"; return $flipped1; } #--------------------- #prints George Bernhard Shaw ---------- Bjoern Borg ---------- Jehud Menuhin ---------- Karl Zeiss ---------- John Woo ----------

You might print out (with the help of Data::Dumper) the contents of your variables at different times in your script to a log file to see exactly what happens when with what data

Btw: What exactly is wrong with the output you get? Are the lines inside some of the comments reversed or is the order of the comments not right?