Keys aren't sorted, so the "first key" won't always be the same.
That said, if you want to compact this a bit, the following should work:
my $deviceType = (keys %data3)[0];
....
my $measInfoID = (keys $data3{$deviceType})[0];
....
my $deviceID = (keys $data3{$deviceType}{$measInfoID})[0];
This is ugly and I would not want to be the guy who comes after you reading this.
Keys will work on hash refs as well as hashes starting with Perl 5.14. If you're older than that, you'll just have to dereference into a full on hash.