my %param = (mo => 1, tu =>1, ..., fr =>1); #### my (%values, @unspecified); while (my $line = <$data_in>) { my $day = get_day($line); # some function to get the day of week from the record if (exists $param{$day) { push @{$values{$day}}, $line; } else { push @unspecified, $line; } }