use strict; my %suits; while (<>) { $suits{$1}++ if /(hearts|clubs|spades|diamonds)/; } print ($_ . "\n") x $suits{$_} for (keys %suits);