perl -M5.010 -Mstrict -F, -wanle ' BEGIN{ $" = "," } our ($rpt, $non_key); if ( ($non_key // "") eq "@F[1..5]"){ print; # this line not right - exercise left to reader } else { $rpt = $F[4] -1; $non_key = "@F[1..5]"; print } '