#!/usr/bin/perl use strict; use warnings; my $f1 = 'file1.txt'; my $f2 = 'file2.txt'; my @pdb; open my $pdb_file, '<', $f2 or die "Can't open the PDB file $f2: $!"; while (my $line = <$pdb_file>){ chomp $line; push @pdb, $line; } close $pdb_file; open my $shifts_file, '<', $f1 or die "Can't open the SHIFTS file $f1: $!"; while (my $line = <$shifts_file>){ chomp $line; my $pdb_line = shift @pdb; # - inner split: get the third element from the $pdb_line # - outer split: get the first element (character) from the # result of the inner split my $criteria = (split('', (split('\s+', $pdb_line))[2]))[0]; # - compare the 2nd element of the file1.txt line against # the above split() operations if ((split('\s+', $line))[1] eq $criteria){ print "$pdb_line\n"; } else { print "**** >$pdb_line< doesn't match >$line<\n"; } } #### 1 H 35 1 A 22 1 H 20 #### A 1 HB2 MET 1 A 2 CA MET 1 A 3 HA MET 1 #### ./app.pl A 1 HB2 MET 1 ****>A 2 CA MET 1< doesn't match >1 A 22< A 3 HA MET 1