#! perl -slw use strict; $/ = 'Drive'; while( ) { next if $. == 1; if( m[ (?=^.*Tray \s+ (.*?) \n ) (?=.*Raw \s capacity: \s+ (.*?) \n ) (?=^.*Unassigned) ]xs ) { print "$1 : $2" } elsif( !m[Assigned] ) { printf STDERR "Badly formatted record:\n%s\n%s\n%s\n\n", '-' x 40, $_, '-' x 40; } } __DATA__ Drive at Tray 0, Slot 1 Raw capacity: 68.366 GB Usable capacity: 67.866 GB Current data rate: 2 Gbps Product ID: ST373453FC Mode: Assigned Drive at Tray 0, Slot 2 Raw capacity: 68.366 GB Usable capacity: 67.866 GB Current data rate: 2 Gbps Product ID: ST373453FC Mode: Unassigned Drive at Tray 0, Slot 3 Mode: Unassigned Usable capacity: 67.866 GB Current data rate: 2 Gbps Product ID: ST373453FC Raw capacity: 68.366 GB Drive at Tray 0, Slot 4 Mode: Unassigned Other random junk: some Usable capacity: 67.866 GB Current data rate: 2 Gbps Product ID: ST373453FC Raw capacity: 68.366 GB Drive at Tray 0, Slot 5 Raw capacity: 68.366 GB Mode: Unassigned Drive at Tray 0, Slot 6 Raw capocity: 68.366 GB Usable capacity: 67.866 GB Current data rate: 2 Gbps Product ID: ST373453FC Mode: Unassigned #### P:\test>junk3 0, Slot 2 : 68.366 GB 0, Slot 3 : 68.366 GB 0, Slot 4 : 68.366 GB 0, Slot 5 : 68.366 GB Badly formatted record: ---------------------------------------- at Tray 0, Slot 6 Raw capocity: 68.366 GB Usable capacity: 67.866 GB Current data rate: 2 Gbps Product ID: ST373453FC Mode: Unassigned ----------------------------------------