@files = qw(model4run1 model2run1 model4run2 model1run1); my $first = shift(@files); my $combined = $first; foreach (@files) { $combined &= $_; } $combined ^= $first; $combined =~ s/[^\x00].*//; my $prefix = substr($first, 0, length($combined)); print qq{Prefix is "$prefix"\n};