use strict; use warnings; $/ = 'INPUT SEQUENCE='; while () { chomp; next unless length; next unless s/^(\d+)\n//; print "Start of file seq$1.dat\n"; print "$_\n"; } __DATA__