if (exists $hash2{$samekeys}) { ntSpacer ($hash2{$samekeys}); } # ... sub ntSpacer { my $myseq = shift; # ... do other stuff }