--- beginning of data --- 1-2,3-4,2-5 2-1,2-5 3-5,1-9,2-2,4-8 --- end of data --- use warnings; use strict; while (<>) { chomp; my @dashpairs = split(/,/); foreach my $dashpair (@dashpairs) { my ($num1, $num2) = split(/-/,$dashpair); print "$num1 - $num2\n"; } }