http://qs1969.pair.com?node_id=657632


in reply to how to split

If you can guarantee that the greater-than sign won't appear in your data, then you might as well use that as your end-of-line marker (your example shows confused usage of this, so you might want to look up the 'slurp' idiom). Each read from the file gets one set of results (the first read is blank, because we've set '>' as an end of line marker, but we're checking our data so it's okay). This can then be split to header/line data and pushed to the array.

Note that the whole thing is in curly brackets so that our value for $/ gets restored for any subsequent code (really, look up the slurp idiom.)

use strict; use warnings; use Data::Dumper; my (@header, @lin); { open FILE, "/home/guest/align.txt" or die("Error reading file: $!"); local $/ = '>'; while (my $result_set = <FILE>) { $result_set =~ s/>$//; # trim trailing EOL marker if ($result_set =~ m/^(.*?)(Query:.*)$/s) { push @header, $1; push @lin, $2; } } }; print Dumper(\@header); print Dumper(\@lin);
---
my name's not Keith, and I'm not reasonable.