foreach $msg_id (keys(%$Messages)) { my $MsgContent = $imap->get($msg_id); #my $Inhalt = $imap->get($msg_id); # print $Inhalt; PrintList(@$MsgContent); } sub PrintList { # Assign parameter to a local variable my (@lines) = @_; # Declare local variables my ($from, $line, $subject, $body); # Check each line in the header foreach $line (@lines) { if($line =~ m/^From: (.*)/) { # We found the "From" field, so let's # get what we need $from = $1; $from =~ s/"|<.*>//g; $from = substr($from, 0, 39); } elsif( $line =~ m/^Subject: (.*)/) { # We found the "Subject" field, so let's # get what we need $subject = $1; $subject = substr($subject, 0, 29); } elsif( $line =~ m/^Body: (.*)/ ) { $body = $1; $body = substr($body, 0, 29); #print $body; } # If we have parsed the "From" and "Subject" # field, then we don't need to keep on going. # Let's quit the loop here. last if( defined($subject) && defined($from) && defined($body) ); } # Print the result printf "From: %-40s Subject: %s\nInhalt: %s\n", $from, $subject, $body; }# end: PrintList()