use strict; use warnings; use Cwd; my @operations = ( { label => 'Harcoded font size value !!', test => sub { $_[0] =~ /font-size\s*(:|=)\s*[^%]+$/ }, }, { label => 'Forced Line height value !!', test => sub { $_[0] =~ /line-height/ }, }, { label => 'position absolute !!', test => sub { $_[0] =~ /position\s*(:|=)\s*absolute/ }, }, ); my $dirpath = getcwd; my @filepaths = glob( "$dirpath/*.css" ); print "no css files\n" unless @filepaths; for my $filepath ( @filepaths ) { print "\n>>> $filepath <<<\n"; $_->{count} = 0 for ( @operations ); # set or reset counts. open my $filehandle, '<', $filepath or die "could not open '$filepath': $!"; while ( my $line = <$filehandle> ) { $_->{test}->( $line ) and $_->{count}++ for ( @operations ); # for each operation, call the test and increment count if it returns true. } close $filehandle; print "$_->{label} $_->{count} Instance found\n" for ( @operations ); # for each operation, print the outcome. }