in reply to ranking number of occurances

I would do this in such a way:

#!/usr/bin/perl -w use strict; my $bit="ace"; my (%hash); while (<DATA>) { while($_ =~ /$bit/g) { $hash{$_}++; } }

And then you can put it into an array, where on position i is a reference to array of lines having i occurences of $bit:

my $bit="ace"; my (%hash, @rank); while (<DATA>) { while($_ =~ /$bit/g) { $hash{$_}++; } push @{$rank[$hash{$_}]}, $_; } # see how the structure looks like # use Data::Dumper; # print Dumper \@rank; for(@rank) { for(@$_) { print; } }