You are viewing the version of this documentation from Perl 5.14.1. View the latest version
given BLOCK

given is analogous to the switch keyword in other languages. given and when are used in Perl to implement switch/case like statements. Only available after Perl 5.10. For example:

use v5.10;
given ($fruit) {
    when (/apples?/) {
        print "I like apples."
    when (/oranges?/) {
        print "I don't like oranges."
    default {
        print "I don't like anything"

See "Switch statements" in perlsyn for detailed information.