http://www.perlmonks.org?node_id=11124605


in reply to How to Split on specific occurrence of a comma

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11124600 use warnings; my $line; my @teams; while ( $line = <DATA> ) { chomp $line; if ($line =~ /^#/ || $line =~ /^\s*$/) { next; } $line =~ s/^[^=]*\=//; push @teams, map [ split /,/ ], "$line," =~ /((?:.*?,){1,3})/gx; } use Data::Dump 'dd'; dd \@teams; __DATA__ Teams=PATRIOTS,BILLS,DOLPHINS,JETS,COWBOYS,GIANTS,EAGLES,REDSKINS,BENG +ALS,OILERS,STEELERS,BROWNS,SEAHAWKS,RAMS,49ERS,RAIDERS

Outputs:

[ ["PATRIOTS", "BILLS", "DOLPHINS"], ["JETS", "COWBOYS", "GIANTS"], ["EAGLES", "REDSKINS", "BENGALS"], ["OILERS", "STEELERS", "BROWNS"], ["SEAHAWKS", "RAMS", "49ERS"], ["RAIDERS"], ]