while( ) { next if $. < 5; chomp; next if ! length; last if /^END/; my @fields = unpack '(a7x)2a7', $_; # Do something with the fields. }