#!/usr/bin/perl use strict; use warnings; my @data; while() { my @row = split /,/,(/(.*)\n?/)[0]; # <-- nice and clear, right? shift(@row); push(@data,@row); } print join "\n", @data; __DATA__ 1,2,3,4 2,3,4,5 3,4,5,6