#!/usr/bin/perl use warnings; use strict; my %options = ( one => \&one, two => \&two, three => \&three, ); my $ret; # return code from the sub while(chomp(my $opt = )){ if(exists $options{$opt}) { $ret = &{$options{$opt}}; last if $ret == 0; } else { default(); } } sub one { print "one\n"; return 1; } sub two { print "two\n"; return 1; } sub three { print "three and break the loop\n"; return 0; } sub default { print "Default\n"; }