#!/usr/bin/perl use warnings; use strict; use v5.10; my @data = ('foo', 'bar', 'baz'); for my $element (@data) { given ($element) { when ('foo') { # Do foo things print("foo here\n"); # force common ending routine $_ = 'MAGIC_foobar'; continue; } when ('bar') { # Do bar things print("bar here\n"); # force common ending routine $_ = 'MAGIC_foobar'; continue; } when ('baz') { # Do baz things print("baz here\n"); } when ('MAGIC_foobar') { # Do common ending things here print("foobar ending here\n"); } } }