It looks like you want something like:
#!/usr/local/bin/perl
use strict;
use warnings;
my $resfile = shift;
my $csafile = shift;
open my $RESFILE, '<', $resfile or die "unable to open $resfile: $!\n"
+;
my %hashlookup;
while ( <$RESFILE> ) {
my ( undef, $num, $str ) = split;
$hashlookup{ substr( $str, 0, 5 ) . " $num" } = 1;
}
close $RESFILE;
open my $CSAFILE, '<', $csafile or die "unable to open $csafile: $!\n"
+;
while ( <$CSAFILE> ) {
chomp;
my ( $pdb, $chain, $csanum ) = ( split /,/ )[ 0, 3, 4 ];
my $key = "$pdb$chain $csanum";
print "$key\n" if $hashlookup{ $key };
}
close $CSAFILE;