chomp $key; # don't care about trailing newline, if any. foreach my $combine (keys %$self) { if (substr($key, 0, length $combine) eq $combine) { print "Found (prefix $combine): ", substr ($key, length $combine), "\n"; } if (substr($key, -length $combine) eq $combine) { print "Found (suffix $combine): ", substr ($key, 0, length($key) - length $combine), "\n"; } }