#!/usr/local/bin/perl use strict; use warnings; # # I want to shove the string NULL into place to make # my split work as expected. # # Ie if I split $line I only get 3 fields when I want 9. # I want an empty/null field to be set to null. # my $line="root:XXXXXXXXXXXXX:12103::::::"; # I want the above to become This: print "My Goal: root:XXXXXXXXXXXXX:12103:NULL:NULL:NULL:NULL:NULL:NULL\n\n"; print "\nWhy does this not work?\n"; print "\tBEFORE\t$line\n" if ( $line =~ /^root:/ ); # UGLY UGLY UGLY UGLY. you have a better idea? $line=~s/::/:NULL:/g; $line=~s/:$/:NULL/g; print "\tAFTER\t$line\n" if ( $line =~ /^root:/ ); $line="root:XXXXXXXXXXXXX:12103::::::"; print "\nThis is an ugly ugly ugly solution:\n"; print "\tBEFORE\t$line\n" if ( $line =~ /^root:/ ); # UGLY UGLY UGLY UGLY. you have a better idea? $line=~s/::/:NULL:/g; $line=~s/::/:NULL:/g; # argh! $line=~s/:$/:NULL/g; print "\tAFTER\t$line\n" if ( $line =~ /^root:/ );