>cat demo.pl #!/usr/bin/perl use v5.12; use warnings; our $endFlag; END { if ($endFlag) { say "End flag is set, have to so some cleanup"; say "Wash, rinse, repeat" for 1..5; } else { say "Nothing to do"; } } $endFlag = $ARGV[0]; say "How will this end?"; >perl demo.pl 0 How will this end? Nothing to do >perl demo.pl 1 How will this end? End flag is set, have to so some cleanup Wash, rinse, repeat Wash, rinse, repeat Wash, rinse, repeat Wash, rinse, repeat Wash, rinse, repeat >