probe.pl < probe_input.file > output.file #### #! C:\Perl\bin\perl use strict; use warnings; my $target_name = ''; my %probes; while (<>) { if ( /:(\d{6})_/ ) { #this line has a target name if ( $target_name ne $1 ) { $target_name = $1; print STDERR "$target_name\n"; } } if ( /\b([ACGT]{20})/ ) { # this line has a probe string my $probe = $1; print STDERR "$probe\n"; push @{$probes{$target_name}}, $probe; } } # printing to STDOUT with redirection on the command line # will save results in an output file (whereas printing to # STDERR goes to the shell window -- unless you use a bash # or bourne-style shell, which allows you to redirect # STDERR to a separate file, using "2> errlog.file") for (sort{ @{$probes{$b}} <=> @{$probes{$a}} } keys %probes) { print "$_, ", join(", ", sort @{$probes{$_}}), "\n"; }