1 2 2 5 4 4 4 4 4 3 4 4 1 1 5 6 4 change to 1 2 0 0 2 0 5 0 0 0 4 4 4 4 0 0 4 0 0 0 3 0 0 0 4 4 0 0 1 0 0 0 0 0 1 5 6 0 4 0 0 0 0 0 #### #use strict #use warning open(IN1, "tmp01") || die "Cannot open this file"; @lines = ; $i = 0; for (@lines) { $lines[$i]=~s/\s\s+/\t0\t/g; $thislines[$i]=$lines[$i]; print $thislines[$i]; $i++; } open(OUT, ">tmp02") || die "Cannot open this file"; for $thisline(@thislines){ print OUT $thisline;} close(OUT); close(IN1);