#!/usr/bin/perl use strict; use warnings; use feature 'say'; my @array = ("backup", undef, "backup"); sub backItUp { say "I am backing it up!" if ($_[0] eq "backup"); } foreach my $element (@array) { eval { die if !defined $element; backItUp( $element ); 1; } or do { my $error = $@ || 'Unknown failure'; warn "Could not backup - $error"; }; } __END__ $ perl test.pl I am backing it up! Could not backup - Died at test.pl line 14. I am backing it up!