#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use feature 'say'; my @array = ("91:", "86:", "184:", "430:", "391:", "254:", "121:", "192:", "404:", "12:", "87:", "638:", "417:", "129:", "549:", "548:", "122:", "443:", "378:", "365:", "665:", "148:", "185:", "88:", "629:", "637:", "149:", "625:", "635:", "627:", "650:", "468:", "92:", "618:", "212:", "85:", "628:", "171:", "649:", "15:", "61:", "169:", "104:", "202:", "523:", "60:", "672:", "291:", "658:", "59:", "547:", "491:", "234:", "411:", "620:", "581:", "414:", "14:", "412:", "416:", "345:", "626:", "457:", "72:", "384:", "371:", "9:", "580:", "436:", "356:", "385:", "58:", "669:", "388:", "386:", "390:", "636:", "619:", "16:", "413:", "17:", "524:", "579:", "624:", "90:", "471:", "410:", "551:", "289:", "387:", "531:", "64:", "166:", "211:", "467:", "415:", "232:", "550:", "362:", "375:", "401:", "359:", "372:", "398:", "360:", "364:", "399:", "403:", "373:", "377:", "18:", "118:", "585:", "427:", "424:", "586:", "469:", "425:", "429:", "13:", "423:", "500:", "62:", "109:", "19:", "539:", "499:", "532:", "400:", "63:", "361:", "374:", "73:", "449:", "175:", "426:", "89:", "507:", "397:", "389:", "582:", "475:", "20:", "22:", "541:", "492:", "503:", "555:", "595:", "596:", "450:", "23:", "611:", "509:", "3:", "485:", "24:", "438:", "442:", "440:", "484:", "117:", "32:", "437:", "31:", "663:", "339:", "535:", "21:", "470:", "439:", "525:", "172:", "40:", "65:", "487:", "50:", "517:", "597:", "545:", "516:", "402:", "347:", "614:", "540:", "613:", "346:", "67:", "363:", "583:", "376:", "428:", "71:", "615:", "332:", "271:", "5:", "508:", "74:"); while (<>) { chomp; # say "$.\t$_"; my @line = split /\s+/; # Matches one or more white space # print Dumper \@line; foreach my $element (@line) { if (index($element, ':') != -1) { my @tmp = split /:/, $element; my $match = $tmp[0] . ':'; if ( grep( /^$match$/, @array ) ) { say "Found it: $match$tmp[1]"; } } } } __END__ $ perl test.pl in.txt Found it: 3:0.33582025 Found it: 5:65.316997 Found it: 9:28 Found it: 12:5 Found it: 13:4328.520884 Found it: 14:5279.218852 Found it: 15:7434.371708 Found it: 16:7829.126536 Found it: 17:7560.24877 Found it: 18:7380.518025 Found it: 19:7094.262906 Found it: 20:6916.621367 Found it: 21:6198.40255 Found it: 22:11858.88819484 Found it: 23:15547.317962699 Found it: 24:23174.9885578928 Found it: 31:419.275504 Found it: 32:463.700544 Found it: 40:83.0884742406 Found it: 50:8977.2048903741 Found it: 58:128.1944444444 Found it: 59:155.2777777778 Found it: 60:253.1111111111 Found it: 61:311 Found it: 62:335.75 Found it: 63:328.4722222222 Found it: 64:338.4166666667 Found it: 65:318.0277777778 Found it: 67:75.9389628772 Found it: 71:44.7351998225 Found it: 72:47.3110129808 Found it: 73:42.4806162036 Found it: 74:42.4332599202 Found it: 85:7.3557105965 Found it: 86:7.6016482623 Found it: 87:7.5850301982 Found it: 88:7.4495976828 Found it: 89:7.3768447337 Found it: 90:7.4461809487 Found it: 91:7.3609459641 Found it: 92:7.2909765644 Found it: 104:147.1672932848 Found it: 109:161.9295657107