use strict; my @devices; undef $/; foreach (split /\n\s\s\b/, ) { # you now have the whole record in $_ # do with it as you please }