foreach my $combine (sort keys %$self) { if($key =~ /^$combine(.*)$/) { print "Found (prefix $combine): $1\n"; } if($key =~ /^(.*)$combine$/) { print "Found (suffix $combine): $1\n"; } }