#!/usr/bin/perl my $destination = '+123'; if($destination eq 'show') { $show = 1; $destination = shift @ARGV; utf8::decode($destination); $sms = join(" ", @ARGV); # POSITION (A) my ($id, $phone) = check_mobiletype($destination) || die "ID not found"; # POSITION (C) print $id, $phone, "\n"; # ID is not printed } else { $sms = join(" ", @ARGV); die "No text" unless $sms; my ($id, $phone) = check_mobiletype($destination) || die "ID not found"; print $id, ' ', $phone, "\n"; } exit; sub check_mobiletype { my $destination = shift; if($destination =~ /^\+/ && $destination !~ /^\+{1}.*\D/) { print "Type phone number\n"; my $id = get_contacts_id_by_mobilephone($destination) || return 0; my $phone = get_mobilephone($id) || return 0; # POSITION (B) print $id, ' ', $phone, "\n"; # ID and phone are printed return ($id, $phone); } elsif($destination =~ /\d/ && $destination !~ /\D/) { #say "Type ID"; my $id = $destination; my $phone = $tcrm->get_mobilephone($id) || return 0; return ($id, $phone); } } sub get_mobilephone { return '+49121212121'; } sub get_contacts_id_by_mobilephone { return 123456; }