FLAGS (\Seen) UID 42 RFC822.TEXT {234565} this is a bunch of string data, but it also contains some binary data...it's not actually IMAP code, it's an internal app that works similarly, but a lot more people are more familiar with IMAP... ..snip.. a lot more string RFC822.SIZE 234565 INTERNALDATE " 21 FEB 2016 12:23:23 +1000") #### while( $sz > 32760 ) { $m =~ /(^.{32760})/g; print $FH $1; $sz -= 32760; } $m =~ /(^.{$sz})/g; print $FH $1;