in reply to Help with substitution - - 15 Characters from the left

If there is only one data field that can contain commas, I would recommend a slightly different approach.

Split the line up on every comma.
Grab the last M fields from the back.
Grab the first N fields from the front.
Join whatever is left using commas into a single field
Join the three pieces together with tabs.

Here is a quick example to get you up to speed.

#!/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 difficul +t "company" data my $middlefield = join(',',@middle); # join the middle portion back t +ogether 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";
I didn't quite understand your regex, but if you want to collapse multiple spaces down into a single one you might try s/\s+/ /g.

-Blake