#!/usr/bin/perl use warnings; use diagnostics; use strict; my %opcodes = ('add'=> sub{ print "the add opcode was passed operands: @_\n"; print "The opcode reported was add with hex value 4\n";}, 'sub'=> \&opcode_sub, ); while (my $instruction = ) { my ($opcode, @operands) = split (/\s+/, $instruction); print "\ninstruction: $opcode operands: @operands\n"; print "calling $opcode...\n"; $opcodes{$opcode}->(@operands); # give some data to subroutine #$opcodes{$opcode}->(); # or no args } sub opcode_sub { print "The code for subtract opcode was passed these operands: @_\n"; print "The opcode reported was add with hex value 5\n"; } =outputs instruction: add operands: 5 6 10 calling add... the add opcode was passed operands: 5 6 10 The opcode reported was add with hex value 4 instruction: sub operands: 7 8 calling sub... The code for subtract opcode was passed these operands: 7 8 The opcode reported was add with hex value 5 =cut __DATA__ add 5 6 10 sub 7 8