#!/usr/bin/env perl use strict; use Data::Dumper; my $line; my @teams; my @pending; while ( $line = ) { next if $line =~ /^#/ || $line =~ /^\s*$/; chomp $line; $line =~ s/^[^=]*\=//; push @pending, split /,/, $line; push @teams, [splice @pending, 0, 3] while @pending >= 3; } push @teams, \@pending if @pending; print Dumper \@teams; __DATA__ Teams=PATRIOTS,BILLS,DOLPHINS,JETS,COWBOYS,GIANTS,EAGLES,REDSKINS,BENGALS,OILERS Teams=STEELERS,BROWNS,SEAHAWKS,RAMS,49ERS,RAIDERS