#!/usr/bin/perl use strict; my $line = 'john,doe,manager,Pepsi Cola, inc.,Detroit,Michigan'; my @fields = split(/,/,$line); # split on commas my @last2 = splice(@fields,-2); # Grab two fields off the back my @first3 = splice(@fields, 0,3); # Grab three fields from the front my @middle = @fields; # Whatever is left is the difficult "company" data my $middlefield = join(',',@middle); # join the middle portion back together print "First: $_\n" for (@first3); print "Middle: $_\n" for (@middle); print "Last: $_\n" for (@last2); print "\n"; my $newline = join("\t",@first3,$middlefield,@last2); # generate new line print "Old: $line\n"; print "New: $newline\n";