#!/usr/bin/perl -w use strict; my $team_file = shift || 'player'; # you can specify a team file on the command # line or take the default my $scores = 'score'; # get players open TEAM, "< $team_file" or die "Cannot open $team_file for reading: $!"; # the grep ensures that we actually have data chomp( my @players = grep /\w+/, ); close TEAM; # get scores open SCORE, "< $scores" or die "Cannot open $scores for reading: $!"; my %all_scores = map {chomp;split/,/} grep { /[^,]+,[^,]+/ } ; close SCORE; # get player scores for listed players my %player_scores; @player_scores{ @players } = @all_scores{ @players }; while ( my ( $player, $score ) = each %player_scores ) { print "Player: $player\tScore: $score\n"; }