use strict; use warnings; my @lines = map {[split]} ; for my $line (@lines) { for my $wordIndex (0 .. $#$line) { substr $line->[$wordIndex], 0, 0, '$'; print join (' ', @$line), "\n"; substr $line->[$wordIndex], 0, 1, ''; } print "\n"; } __DATA__ one fish, two fish, red fish, blue fish