$line = ' 2 3 4'; $line =~ s#(?= )# #gsi; while ($line =~ s#( ) ( )#$1$2#gsi) { } print $line; o/p:    2    3    4