in reply to Removing element of an array

You can use regular expressions for this. You are using one in your rtrim sub but maybe you haven't explored yet what they can do. For example:
my $account = '12340612121'; print "it matches 406\n" if $account=~/406/;
will identify the pattern "406" in the long string and print "it matches 406"