#!/usr/bin/env perl use v5.14; my @array = (0, 1000..10_000, 'abcd'); for my $element (qw/a ab abc 100 1000 10000 abcd/) { say "With grep:"; if (grep {/^$element$/} @array) { say "Element $element is there"; } else { say "Element $element is not there"; } say "With given-when:"; given ($element) { when (\@array) { say "Element $element is there"; } default { say "Element $element is not there"; } } say ""; }