use strict; use warnings; use Text::xSV; my $xsv = Text::xSV->new (sep => "\t", fh => *DATA); while (my @row = $xsv->get_row ()) { map {s/\s+$//; s/^\s+//} @row; print ">", join ("< >", @row), "<\n"; } __DATA__ 0.000 12 0.232 13 11 text that can have space 1.000 13 0.534 14 12 More text that would be ok 2.000 14 0.876 15 13 yet more text #### >0.000< >12< >0.232< >13< >11< >text that can have space< >1.000< >13< >0.534< >14< >12< >More text that would be ok< >2.000< >14< >0.876< >15< >13< >yet more text<