# Declaration of the data structure my %packet_fields = ( $Idents{ Format_7 } => [qw( ident x y flight_level chksum )], $Idents{ Rotation_Marker } => [qw( ident site_x site_y chksum )], ); # This structure listed for completeness of this example! my %packet_template = ( $Idents{ Rotation_Marker } => "C3 n n n n n n n n n n n n C3", $Idents{ Format_7 } => "C B16 n2 A4 A8 A2 A A A3 C2", ); # Referencing the data structure # code here to read $buffer from STDIN # $ident is extracted from $buffer @packet{ @{$packet_fields{ $ident }} } = unpack ( $packet_template{ $ident }, $buffer);