#!/usr/bin/perl -w use strict; my $bit="ace"; my (%hash); while () { while($_ =~ /$bit/g) { $hash{$_}++; } } #### my $bit="ace"; my (%hash, @rank); while () { while($_ =~ /$bit/g) { $hash{$_}++; } push @{$rank[$hash{$_}]}, $_; } # see how the structure looks like # use Data::Dumper; # print Dumper \@rank; for(@rank) { for(@$_) { print; } }