#!/usr/bin/perl use strict; use warnings; use Data::Dump 'pp'; use Text::CSV; main(); sub main { my $data = shift || return; my $file = "file.txt"; eval { open my $fh, ">", $file or die "Unable to create or open file: $!"; $csv->print($fh, $_) for @{ $data }; close $fh; }; if ($@) { print "ERROR!"; }else { # A message code will be here, using 1114 as sample; my $message = check('1114'); print $message; # I want to print " Exit " <<<<<<<<<<< }; } sub check { my $ck = shift; my %message= ( 'y345' => " Close ", '1223dx' => " Open ", '88888' => " Gone ", 'acb2' => " Available ", '1114' => " Exit ", ); }