in reply to Why do i get an extra (duplicate) array element?-

Post tested input and how you're getting handle <IN>. And if you are not:
use strict; use warnings;

Replies are listed 'Best First'.
Re^2: Why do i get an extra (duplicate) array element?-
by rickman1 (Novice) on Jun 23, 2016 at 20:14 UTC

    From command-line argument. It's a fixed text file, in this case it only contains 4 lines but it can be thousands. The amount is always on that position on every line. The only way i could think of snatching them was through substr.

    open IN, "<$ARGV[0]" or die "Could not open input file '$ARGV[0]' $!";

    Flat text file would be many lines of equal length with the amounts at that same position in every line.

      If you could show us an actual data line(s), then most likely other techniques than substr() could be used. Split with an array slice is often a good approach. Just post your 4 lines within <code>...</code> blocks and we can tell exactly what is going on.