use strict; use warnings; use feature qw(:5.14); my $line_out = ; chomp $line_out; while () { chomp; if ($_=~/^> ([\d\.\-]+)/) { $line_out .= $1; } else { say $line_out; $line_out = $_; } } say $line_out; __DATA__ .06669701$-.1672469$.02157899$.0346167$.65879324$.91614802$.45012441$rs11080516 [... I have abbreviated your data for this post ...]