The problem is probably caused by reading from a file - you get lines (read into @records) as follows:
user1|pass1\n
user2|pass2\n
user3|pass3
note the last line doesn't have a \n at the end, hence chop chops the last char off rather than the \n
Again, the easiest way is to just use chomp rather than chop. Otherwise you could hack it
by doing
# add /n to last record
my $hackyvar = pop @records;
$hackyvar .= "\n";
push @records, $hackyvar;
(you can probably do this in one line but I prefer readable code...)
and then do your foreach loop after that. Hacky, but it works.
But use chomp anyway... |