... my ($now_vgname,$now_label); while ( <$input_handle> ) { if ( /lsattr -El (\w+)/ ) $now_vgname = $1; next; } if ( /label\s+([\/\w]+)/ ) { $now_label = $1; next; } if ( /lvserial_id\s+([\w\.]+)/ ) { $host_info{VG}->{$now_vgname}->{$1}->{LV} = $now_label next; } }