#!usr/bin/perl open ROWS, "< style.txt" or die "Can't read from style.txt"; undef $/; # no input record separator $_ = ; # copy the whole file to default var close ROWS; s/\s*(\w+)[\n\s]+([-.\d]+)[\n\s]+/$1 $2\n/g; # substitute your described input format # with requested output format in the whole text (now $_) open E, "> style1.txt" or die "Can't write in style1.txt"; print E; close E;