use Record; ... my $endianness = get_first_record($file); # or better: put this into the Record::new class method my $record = Record::new($endianness); # returns either a Record_Little_Endian or a Record_Big_Endian object $record->unpack(); # unpacks the record in a way that is endian-transparent ...