#!/usr/bin/perl use 5.016; use warnings; # 1068826 my $data = '>b_comp_seq1 ACGCGGGGGAATTT >b_comp_seq2 ACGGAATT >b_comp_seq3 GGGGGCTTTCACC >b_comp_seq4 TACCGGGAATT'; my @data1 = split /\s/, $data; my $i=0; my ($data1, $fh, $fn); for $_(@data1) { $_ =~ />(.*)/; $fn = $1; if ( $i%2 == 0 ) { open $fh, ">", $fn or warn "Can't open $fh for write, $!"; ++$i; print $fh "$fn \t $data1[$i]"; say " DEBUG: \$fn, \$data1[$i]: $fn, $data1[$i]"; close $fh; } else { ++$i; #ALSO -- # consider how to revert to writing to the first file for comp_seq_5 # if that's the way you wish to order the elements; otherwise, revise # the code above to put the first four sequences and their source # id's into the first file written. } } =head output files contain... b_comp_seq1 ACGCGGGGGAATTT b_comp_seq2 ACGGAATT b_comp_seq3 GGGGGCTTTCACC b_comp_seq4 TACCGGGAATT =cut