in reply to Re^4: Store the outcome of a foreach loop in an array
in thread Store the outcome of a foreach loop in an array

In addition to the comments from the others:

@$lines = join "\n", @$lines;

Basically, this is your issue - you're joining the lines into a single string, which is why your loop runs only once. This line probably isn't necessary - unless you had a specific reason for putting it there? It'd be best if you insert more debugging output - for example, put the use Data::Dumper; $Data::Dumper::Useqq=1; at the top of the program, and then do a print Dumper($lines); before the join, and maybe once more right after the rdfile, to see how the array changes as your program runs.

BTW, it's best if you Use strict and warnings!