#!/usr/bin/perl use warnings; use strict; open(my $in_fh, '<', 'input.txt') or die $!; open(my $out_fh, '>', 'output.txt') or die $!; my %seen_lines; while (<$in_fh>) { chomp; my @columns = split; if ($columns[1] and $columns[1] =~ /^HLA-A/) { my $HLA_Peptide = $columns[1] . $columns[2]; print $out_fh "$_\n" if (!exists $seen_lines{$HLA_Peptide}); $seen_lines{$HLA_Peptide} = 1; } else { print $out_fh "$_\n"; } } close $out_fh; close $in_fh;