#!/opt/bin/perl use Switch; use 5.010; my %is_ready = ('teacher' => "student", 'student' => "teacher"); for(%is_ready){ given($_) { when(/student/) { appear($is_ready{$_}); } when(/teacher/) { appear($is_ready{$_}); } } } sub appear{ $appear = shift; print "$appear is ready, ". $is_ready{$appear} ."\n"; }