#!/usr/bin/perl use strict; use warnings; { local ($,,$\) = (" - ","\n"); while () { chomp; print split(/-/) for split(/,/) } } __DATA__ 1-2,3-4,2-5 2-1,2-5 3-5,1-9,2-2,4-8