#!/usr/bin/perl -w use strict; my $test='A , B , Calcutta '; my @names = split /\s?,\s?/, $test; #split apart $_ = [split /\s(?=<)/, $_] for (@names); #make array refs of each # Above happily learned from merlyn foreach my $name (@names) { foreach (@{$name}){ print "--$_--"; } print "\n"; }