use strict; use warnings; use feature qw( switch say ); sub test_it { my $value = shift; given($value) { when(/aaa/) { return 'wanna' } when(/bbb/) { return 'be' } when(/ccc/) { return 'startin' } default { return 'somethin' } } } foreach my $str (qw[testaaa testbbb testccc testddd]) { say test_it($str); }