use strict; use warnings; my $ish = $ARGV[0]; if ( ! defined $ish ) { die "1: $!"; } ## It helps to know which die? open (ISH, "<", $ish) || die "2: $!"; open (OUT, ">", "out.txt") || die "3: $!"; open (my $LOG, ">", "log.txt") || die "4: $!"; # $/ = "//"; my $no = 0; our %hash = (); while () { my $var = $_; $no++; print $LOG "$no\t$var"; ## This is to help know that you are reading and what it is chomp($var); if ( $var eq "//" ) { if ( %hash ) { my ( $a, $b, $c, $x ) = Process_Hash(); ## You could do more work on %hash here or move the sub here print OUT "$b\t$a\t$c\t$x\n"; } %hash = (); ## Clear %hash for next sequence next; } ## Note: If you data contains real tabs (0x09), then make the '\\' a '\' my ( $key, $value ) = split(/\\t/,$var ); # print $LOG "\t$var => |$key|$value|\n"; $hash{ $key } = $value; } if ( %hash ) { my ( $a, $b, $c, $x ) = Process_Hash(); ## You could do more work on %hash here or move the sub here print OUT "$b\t$a\t$c\t$x\n"; } exit; # optional but I like to see it and be able to search on. ## Process the element of %hash sub Process_Hash { my ( $a, $b, $c, $x ) = ( "", "#", "for-you", "for-you" ); if ( defined $hash{"DEV_STAGE"} ) { $a = $hash{"DEV_STAGE"}; } if ( defined $hash{"PREDICTED_GENE"} ) { $b = $hash{"PREDICTED_GENE"}; } # while (m/\tSTAINED_REGION:\\t(.*?)\tSTAINED_MOL:\t(.*?)\n/g) return( $a, $b, $c, $x ); } 1;