#!/usr/local/bin/perl use Data::Dumper; my $hash = { a => 21, b => 32, c => 43 }; my $array = [ 11,12,13,14]; foreach (1..3){ perform_operationX(); print_data(); } cancel_last_operationX(2); sub perform_operationX { my $letter = chr(97+ int rand(10)); my $number = int rand(100); $hash->{$letter} = $number; shift @$array; } sub print_data{ print Dumper($hash,$array); } sub cancel_last_operationX { my $number_of_operations = shift; ......... UNDO CODE ............. }