#!/usr/bin/perl -w use strict; use Carp; my %h = ( 'one' => 'uno', 'two' => 'dos', 'three' => 'tres', ); my $s = 'foo bar'; sub xyz() { my $arg; my $argNum=0; my $stringOrRef; while(defined($arg = shift)) { if($argNum == 0) { $stringOrRef = $arg; } else { carp "one arg only please"; } $argNum++; } # here is where I test the argument ###################################### if($stringOrRef =~ /^HASH\(/) { print "it's a hash:\n"; foreach my $k (keys %{ $stringOrRef }) { print " $k : $$stringOrRef{$k}\n"; } } else { print "it's a string:\n"; print " $stringOrRef\n"; } } &xyz($s); &xyz(\%h);