use strict; use warnings; use IO::Prompt::Hooked 'prompt'; my @storage = qw( knife wand bow ); my @inventory = qw( axe sword shovel ); while(@inventory) { print "\nYour inventory contains: ( @inventory )\n"; print "Your storage contains: ( @storage )\n"; my $wanted = prompt( message => 'Which item would you like to deposit? (blank to quit):', validate => sub { my $i = lc shift; return 1 if ! length $i; return grep { $i eq $_ } @inventory }, error => "Please input a valid answer: ( @inventory ).\n" ); last unless $wanted; my( $item_index ) = grep { $inventory[$_] eq $wanted } 0 .. $#inventory; die "Couldn't find $wanted\n" unless defined $item_index; # Impossible. push @storage, splice @inventory, $item_index, 1; die "push/splice failure with <$wanted>.\n" if $storage[-1] ne $wanted; # Impossible. } print <<"EOD"; Now inventory and storage respectively contain: ( @inventory ) ( @storage ) EOD #### $ ./mytest.pl Your inventory contains: ( axe sword shovel ) Your storage contains: ( knife wand bow ) Which item would you like to deposit? (blank to quit): swwrd Please input a valid answer: ( axe sword shovel ). Which item would you like to deposit? (blank to quit): sword Your inventory contains: ( axe shovel ) Your storage contains: ( knife wand bow sword ) Which item would you like to deposit? (blank to quit): axe Your inventory contains: ( shovel ) Your storage contains: ( knife wand bow sword axe ) Which item would you like to deposit? (blank to quit): shovel Now inventory and storage respectively contain: ( ) ( knife wand bow sword axe shovel )